Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在桌面应用程序中使用google oauthutill检索联系人_C#_Oauth_Google Api - Fatal编程技术网

C# 在桌面应用程序中使用google oauthutill检索联系人

C# 在桌面应用程序中使用google oauthutill检索联系人,c#,oauth,google-api,C#,Oauth,Google Api,我正在使用oauth从桌面应用程序访问google联系人。我在这里遵循了谷歌的指示:但我遇到了问题 代码如下: OAuthParameters parameters = new OAuthParameters() { ConsumerKey = CONSUMER_KEY,

我正在使用oauth从桌面应用程序访问google联系人。我在这里遵循了谷歌的指示:但我遇到了问题

代码如下:

 OAuthParameters parameters = new OAuthParameters()
                                         {
                                             ConsumerKey = CONSUMER_KEY,
                                             ConsumerSecret = CONSUMER_SECRET,
                                             Scope = SCOPE,
                                             Callback = "http://localhost:10101/callback.htm.txt",
                                             SignatureMethod = "HMAC-SHA1"
                                         };
        OAuthUtil.GetUnauthorizedRequestToken(parameters);
        string authorizationUrl = OAuthUtil.CreateUserAuthorizationUrl(parameters);
        Console.WriteLine(authorizationUrl);
        var win = new GoogleAuthenticationWindow(authorizationUrl,parameters);
        win.ShowDialog();
        OAuthUtil.GetAccessToken(parameters);
在窗口内,我有以下内容:

private void BrowserNavigated(object sender, NavigationEventArgs e)
    {
        if (e.Uri.ToString().Contains("oauth_verifier="))
        {
            OAuthUtil.UpdateOAuthParametersFromCallback(e.Uri.ToString(), m_parameters);
            Close();
        }
    }

在最后一行OAuthUtil.GetAccessTokenparameters;我收到了一个400错误的请求,我不知道为什么…

在玩了很多游戏之后。。。我认为这是访问google api最简单的方法:

Service service = new ContactsService("My Contacts Application");
        service.setUserCredentials("mail@gmail.com", "password");
        var token = service.QueryClientLoginToken();
        service.SetAuthenticationToken(token);
        var query = new ContactsQuery(@"https://www.google.com/m8/feeds/contacts/mail@gmail.com/full?max-results=25000");
        var feed = (ContactsFeed)service.Query(query);
        Console.WriteLine(feed.Entries.Count);
        foreach (ContactEntry entry in feed.Entries)
        {
            Console.WriteLine(entry.Title.Text);
        }

比使用oauth简单得多…

经过多次尝试后。。。我认为这是访问google api最简单的方法:

Service service = new ContactsService("My Contacts Application");
        service.setUserCredentials("mail@gmail.com", "password");
        var token = service.QueryClientLoginToken();
        service.SetAuthenticationToken(token);
        var query = new ContactsQuery(@"https://www.google.com/m8/feeds/contacts/mail@gmail.com/full?max-results=25000");
        var feed = (ContactsFeed)service.Query(query);
        Console.WriteLine(feed.Entries.Count);
        foreach (ContactEntry entry in feed.Entries)
        {
            Console.WriteLine(entry.Title.Text);
        }
比使用oauth简单得多