【问题标题】:ASP.NET site authorization issue with google and youtube api's谷歌和 youtube api 的 ASP.NET 站点授权问题
【发布时间】:2012-12-15 11:06:28
【问题描述】:

我已经在我的网站中实现了几个谷歌 API - 以启用联系人导入和 youtube 上传。 虽然一切都在本地运行良好(在我自己的开发服务器的本地主机下),但通过站点使用它们存在一些问题(托管在 HostGator 和 1and1 上,我到处都遇到相同的错误) - 似乎 身份验证问题。

该站点在 ASP.NET 2.0 上,这些是我得到的错误消息:

  1. Google 联系人错误(使用 AuthSub) - 这发生在我从 google 的 authsub 成功接收到会话令牌之后:

    The remote server returned an error: (401) Unauthorized.
    
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information 
    
    about the error and where it originated in the code. 
    
    Exception Details: System.Net.WebException: The remote server returned an error: (401) Unauthorized.
    
    Source Error: 
    
    
    Line 493:        ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));
    Line 494:
    Line 495:        ContactsFeed feed = service.Query(query);
    Line 496:
    Line 497:        ArrayList emails = new ArrayList();
    
    Source File: d:\inetpub\vhosts\e-koren.com\httpdocs\home-cooking\EmailInvite.aspx.cs    Line: 495 
    
  2. youtube 视频上传错误(使用 ClientLogin):

    Invalid credentials
    
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information 
    
    about the error and where it originated in the code. 
    
    Exception Details: Google.GData.Client.InvalidCredentialsException: Invalid credentials
    
    Source Error: 
    
    
    Line 71: //            try
    Line 72: //            {
    Line 73:                 FormUploadToken _token = request.CreateFormUploadToken(newVideo);
    Line 74: 
    Line 75:                 actionURL.Value = _token.Url + "?nexturl=" + Server.UrlPathEncode(Request.Url.ToString()+"?uuc=");
    
    Source File: d:\inetpub\vhosts\e-koren.com\httpdocs\home-cooking\youtubeUpload.aspx.cs    Line: 73 
    

有人知道它是什么吗?

谢谢, 阿萨夫

【问题讨论】:

    标签: asp.net authentication google-api youtube-api authsub


    【解决方案1】:

    我最终设法解决了它:

    至于第一个错误(authsub 和 google 联系人) - 我将 URI 从“http”更改为“https”:

    // V1
    GAuthSubRequestFactory authFactory = new GAuthSubRequestFactory("cp",gn.ytApplicationName);
    
    authFactory.Token = (String)Session["token"];
    
    ContactsService service = new ContactsService(authFactory.ApplicationName);
    
    service.RequestFactory = authFactory;
    
    ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));
    
    // VERY IMPORTANT! adding HTTPS resolves google's bug (401 error)
    query.Uri = new Uri("https://www.google.com/m8/feeds/contacts/default/full");
    
    ContactsFeed feed = service.Query(query);
    

    关于第二个错误(ClientLogin) - 谷歌似乎已经加强了围绕这种方法的安全措施 - 他们向我想要登录的用户发送一封警告电子邮件 - 只有当他遵循他们授权的几个复杂步骤时访问他的视频。

    我发现这不是一个错误,而是一个政策,我想我也会在那里切换到 AuthSub。

    希望我也能帮助别人...

    :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-17
      相关资源
      最近更新 更多