Google通讯录数据Api 401错误

8 .net c# api contact google-contacts-api

我正在使用Google通讯录数据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);
Run Code Online (Sandbox Code Playgroud)

用户成功登陆后第二次使用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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

该代码工作大约4或5天,但现在它不工作,并得到以下错误

远程服务器返回错误:(401)未经授权.Google.GData.Client.Client.Service.Execute()at Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)at Google.GData.Client.GDataGAuthRequest.Execute()at Google.GData.Client.Service.Query(Uri)在Google.GData.Client.Feed的Google.GData.Client.Service.Query(FeedQuery feedQuery)上的Google.GData.Client.Service.Query(Uri queryUri,DateTime ifModifiedSince)中的queryUri,DateTime ifModifiedSince,String etag,Int64&contentLength)1.get_AtomFeed() at Google.GData.Client.Feed1.d__0.MoveNext()在GoogleContacts.Page_Load(Object sender,EventArgs e)的d:\ Working Folder\API的\ ContactImporter\GoogleContacts.aspx.cs:第25行,在System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp) System.Web.UI.Control上的System.Web.UI.Control.OnLoad(EventArgs e)上的System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,EventArgs e)中的,Object o,Object t,EventArgs e). System.Web.UI.Page.ProcessRequestMain中的LoadRecursive()(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)

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

Mic*_*ann 2

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