【发布时间】:2011-10-23 05:48:09
【问题描述】:
我正在使用 Google Contacts Data Api 按照此处的文档获取所有用户联系人https://developers.google.com/google-apps/contacts/v3/
首先我使用 Google Auth 使用以下代码对应用程序的用户进行身份验证
string authSubUrl = AuthSubUtil.getRequestUrl("http://localhost:62439/ContactImporter/GoogleContacts.aspx", "https://www.google.com/m8/feeds/", true, true);
Response.Redirect(authSubUrl);
用户成功登录后,我使用 Google 提供的请求令牌重定向到 GoogleContacts.aspx 页面,然后尝试通过以下代码获取联系人
if (!string.IsNullOrEmpty(Request["token"]))
{
GAuthSubRequestFactory authFactory = new GAuthSubRequestFactory("cp", "alpha");
RequestSettings rs = new Google.GData.Client.RequestSettings("alpha",Request["token"]);
ContactsRequest cr = new ContactsRequest(rs);
Feed<Contact> f = cr.GetContacts();
foreach (Contact entry in f.Entries)
{
foreach (EMail email in entry.Emails)
{
Response.Write("\n" + email.Address);
}
}
}
该代码从大约 4 到 5 天开始工作,但现在它无法正常工作,并让我出现以下错误
远程服务器返回错误:(401) Unauthorized。 在 Google.GData.Client.GDataRequest.Execute() 在 Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter) 在 Google.GData.Client.GDataGAuthRequest.Execute() 在 Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince, String etag, Int64& contentLength) 在 Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince) 在 Google.GData.Client.Service.Query(FeedQuery feedQuery) 在 Google.GData.Client.Feed
1.get_AtomFeed() at Google.GData.Client.Feed1.d__0.MoveNext() 在 d:\Working Folder\API's\ContactImporter\GoogleContacts.aspx.cs:line 25 中的 GoogleContacts.Page_Load(Object sender, EventArgs e) 在 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,对象 o,对象 t,EventArgs e) 在 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(对象发送者,EventArgs e) 在 System.Web.UI.Control.OnLoad(EventArgs e) 在 System.Web.UI.Control.LoadRecursive() 在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
关于如何解决该错误的任何建议?
【问题讨论】:
-
一个话题已经在谷歌论坛上发起了:here。也许谷歌会回答我们的问题......
-
任何带有完整源代码示例的最终解决方案?
标签: c# .net api contact google-contacts-api