【问题标题】:using google oauthutill in a desktop application to retrieve contacts在桌面应用程序中使用 google oauthutill 检索联系人
【发布时间】:2011-10-03 18:32:48
【问题描述】:

我正在使用 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 bad request 错误,我不知道为什么...

【问题讨论】:

    标签: c# oauth google-api


    【解决方案1】:

    在玩了很多之后...我认为这是访问 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 容易得多...

    【讨论】:

      猜你喜欢
      • 2012-03-12
      • 1970-01-01
      • 1970-01-01
      • 2015-01-08
      • 1970-01-01
      • 2017-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多