我正在使用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(参数);)我收到400错误的请求错误,我不明白为什么......
答案 0 :(得分:0)
经过多次游戏......我认为这是访问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要容易得多......