【问题标题】:Google Contacts Data Api 401 errorGoogle 通讯录数据 API 401 错误
【发布时间】: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.Feed1.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)

关于如何解决该错误的任何建议?

【问题讨论】:

标签: c# .net api contact google-contacts-api


【解决方案1】:

这不是您要寻找的答案,但我可以让您放心。 您的代码没有任何问题。谷歌最近在没有通知的情况下关闭了联系人 API 服务。 没有人知道他们是否已经过时或出于其他原因将其删除。 截至昨天,他们甚至删除了 API 文档。然而,指向它的链接仍然发布在他们的 API 列表中https://developers.google.com/google-apps/app-apis,不再有任何文档,谷歌也没有解释为什么它被关闭。希望这不是永久性的事情。 Google 尚未就此问题回答开发者。

【讨论】:

  • 我希望我能在赏金到期之前注意到这个回复。它实际上回答了这个问题。对不起,我错过了你。
  • 直到今天它还在下降?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-30
  • 2011-09-02
  • 2016-07-23
  • 1970-01-01
相关资源
最近更新 更多