我刚开始使用 google contacts api,找不到如何使用身份验证内容的示例。
我使用了 Google Contacts API version 3.0了解联系人 API 基本工作流程的文档,但我不知道如何使用身份验证 token 。
在网上搜索后,我找到了教程 Google OAuth2 C#但在本教程中,他们使用的是 UserCredential
对象。在 Google Contacts API 3.0 版文档中,他们使用了 RequestSettings
对象。该对象有一个接受 ApplicationName 和 GDataCredentials
对象的构造函数。
所以我尝试了下面的代码:
GDataCrendentials credentials = new GDataCredentials(CLIENTID);
credentials.Username = "<my gmail username>";
this._requestSettings = new RequestSettings(GetApplicationName, _credentials);
我从发布的第二个链接获得的 ClientId。
所以我尝试使用代码访问我的联系人:
Feed<Google.Contacts.Contact> f = _contactsRequest.GetContacts();
IList<IContact> mappedContacts = new List<IContact>();
foreach (var contact in f.Entries)
{
//do some stuff with it
}
使用这段代码,我在 foreach 处得到一个 Google.GData.Client.GDataRequestException:
{"Execution of request failed: https://www.google.com/m8/feeds/contacts/default/full"}
你能给我一个建议,这里有什么问题吗?
最佳答案
GData .NET 客户端库中包含一个 OAuth2 示例:
相关源代码位于此处:
https://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/src/core/oauthutil.cs#200
关于c# - 谷歌通讯录 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26238329/