我已经实现了几个谷歌api在我的网站-启用联系人导入和youtube上传。虽然一切工作在本地(在我自己的开发服务器的localhost),有一些问题使用他们通过网站(托管在HostGator和1and1,我得到同样的错误无处不在)-似乎身份验证问题。
网站是在ASP上。这些是我得到的错误消息:
-
谷歌联系人错误(使用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:inetpubvhostse-koren.comhttpdocshome-cookingEmailInvite.aspx.cs Line: 495
-
上传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:inetpubvhostse-koren.comhttpdocshome-cookingyoutubeUpload.aspx.cs Line: 73
有谁知道会是什么吗?
谢谢,Asaf
我终于解决了这个问题:
对于第一个错误(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。
希望我也能帮助到别人。
:)