2012-12-31 181 views
0

我已經在我的網站上實現了幾個谷歌API - 以禁止聯繫人導入和YouTube上傳。當在本地(在我自己的開發服務器的本地主機下)一切正常工作時,使用它們通過站點(HostGator和1and1託管,我在任何地方都收到相同的錯誤)有一些問題 - 似乎是 身份驗證問題。ASP.NET網站授權問題與谷歌和YouTube的API

該網站是在ASP.NET 2.0,這些都是錯誤的MSG我得到:

  1. 錯誤的谷歌聯繫人(使用AuthSub) - 這種情況發生後,我順利地收到來自谷歌的的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. 錯誤爲(是使用ClientLogin)的YouTube視頻上傳:

    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 
    

任何人都知道它會是什麼?

感謝, 阿薩夫

回答

0

我設法最終解決售後服務它:

作爲第一個錯誤(的AuthSub和谷歌聯繫人) - 我從 「HTTP」 爲 「https」 改變了URI:

// 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的) - appearantly谷歌已經收緊圍繞這種方法的安全性措施 - 他們發送警告電子郵件,我想通過登錄用戶 - 只有當他如下幾個複雜的步驟他們授權訪問他的視頻。

因爲我發現這不是一個錯誤,而是一個政策,我想我也只是在那裏切換到AuthSub。

希望我能幫助別人太...

:)