开发者

using google oauthutill in a desktop application to retrieve contacts

I am using oauth to get acces to google contacts from a desktop application. I have followed the instruction from google here: http://code.google.com/int开发者_StackOverflowl/iw-IL/apis/gdata/docs/auth/oauth.html#Examples but I am having problems

here is the code:

 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);

inside the window I have the following:

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

at the last line (OAuthUtil.GetAccessToken(parameters);) I am getting a 400 bad request error and I have no idea why...


After much playing around... I think this is the easiest way to access 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);
        }

much easier than using oauth...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜