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

标签 c# oauth google-api

我正在使用 oauth 从桌面应用程序获取对 google 联系人的访问权限。我在这里遵循了谷歌的说明:http://code.google.com/intl/iw-IL/apis/gdata/docs/auth/oauth.html#Examples但是我有问题

代码如下:

 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.GetAccessToken(parameters);) 我收到 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 容易得多...

关于c# - 在桌面应用程序中使用 google oauthutill 检索联系人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7639135/

相关文章:

c# - 不能通过并发线程访问破坏数据

ios - Evernote iOS SDK - 如何使用 token 进行身份验证?

ios - 优步 API iOS OAuth 2.0

google-analytics - 如何从 Google Analytics GAPI API 获取 “Visitors Flow” 数据?

javascript - 使用 BigQuery API 客户端时的授权

php - 如何在开源(Github + Heroku)应用程序中保护 Google API Key

c# - 应用下载的纹理后,PNG 文件在 Unity 中增长并通过 EncodeToPNG 转换回 PNG

c# - 数据类型 text 和 varchar 在等于运算符中不兼容

C# - 在流畅的界面中从列表中添加值

laravel - Nuxt Auth +名流手动登录