Google通讯录数据Api 401错误

时间:2011-08-09 13:32:55

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

我正在使用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);

用户成功登录后第二次使用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)未经授权。      在Google.GData.Client.GDataRequest.Execute()      at Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)      在Google.GData.Client.GDataGAuthRequest.Execute()      在Google.GData.Client.Service.Query(Uri queryUri,DateTime ifModifiedSince,String etag,Int64&amp; contentLength)      在Google.GData.Client.Service.Query(Uri queryUri,DateTime ifModifiedSince)      在Google.GData.Client.Service.Query(FeedQuery feedQuery)      at Google.GData.Client.Feed 1.get_AtomFeed() at Google.GData.Client.Feed 1.d__0.MoveNext()      在d:\ Working Folder \ API的\ ContactImporter \ GoogleContacts.aspx.cs中的GoogleContacts.Page_Load(Object sender,EventArgs e):第25行      在System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,Object o,Object t,EventArgs e)      在System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,EventArgs e)      在System.Web.UI.Control.OnLoad(EventArgs e)      在System.Web.UI.Control.LoadRecursive()      在System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)

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

0 个答案:

没有答案
相关问题