Question

I have implemented several google APIs in my website - to enbale contacts import and youtube uploads. while everything works great locally (under my own development server's localhost), there are some problems using them thru the site (hosted on both HostGator and 1and1 and i get the same errors everywhere) - seems like authentication problems.

the site is on ASP.NET 2.0 and these are the error msgs i get:

  1. Error For google contacts (using AuthSub) - this happens after the I successfully receive a session token from google's 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. Error For youtube video uploading (using 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 
    

Anyone knows what could it be?

Thanks, Asaf

Was it helpful?

Solution

I managed to slove it eventually:

as for the first error (authsub and google contacts) - I changed the URI from "http" to "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);

about the 2nd error (ClientLogin) - appearantly google have tightened the security measures around this kind of method - they send a warning email to the user that I wanted to log in through - and only if he follows several complex steps they authorize access to his videos.

As I found out this is not an error, but a policy, I think I'll just switch to AuthSub there too.

Hope I could help someone else too...

:)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top