Google Data API Authentication

I am trying to get my Django application (DO NOT use the Google mechanism) to retrieve data from Google contacts using the Google Contact Data API. authentication documentation as well as Data API Python docs

The first step (AuthSubRequest), which receives a one-time token, works fine. The next step (AuthSubSessionToken), which is a one-time update token for the session token. The python API UpgradeToSessionToken () just didn't work for me, this gave me a NonAuthSubToken exception:

gd_client = gdata.contacts.service.ContactsService() gd_client.auth_token = authsub_token gd_client.UpgradeToSessionToken() 

As an alternative, I want to make it work using "manually" by creating an HTTP request:

 url = 'https://www.google.com/accounts/AuthSubSessionToken' headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'AuthSub token=' + authsub_token, 'User-Agent': 'Python/2.6.1', 'Host': 'https://www.google.com', 'Accept': 'text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2', 'Connection': 'keep-alive', } req = urllib2.Request(url, None, headers) response = urllib2.urlopen(req) 

this gives me another error:

HTTP Error 302: The HTTP server returned a redirect error that will lead to an infinite loop. Last 30x error message: Moved temporarily

What am I doing wrong here? I would appreciate help / advice / suggestions using any of the methods I'm trying to use: Python API call (UpgradeToSessionToken) or manually construct an HTTP request with urllib2.

+6
python django google-api gdata gdata-api
source share
3 answers

According to the 2.0 documentation, there is a set of python examples here ...

Running sample code

The full working sample client, containing all the code sample shown in this document, is available in the Python client library distribution under the samples/contacts/contacts_example.py directory.

The client example performs several contact operations to demonstrate the use of the contact data API.

Hope he points you in the right direction.

+4
source share

I recently had a similar problem. The mine has been fixed by setting β€œsafe” to β€œtrue”.

  next = 'http://www.coolcalendarsite.com/welcome.pyc' scope = 'http://www.google.com/calendar/feeds/' secure = True session = True calendar_service = gdata.calendar.service.CalendarService() 
+1
source share

There are four different authentication methods. Is it really important that you use AuthSub? If you can't get AuthSub to work, consider ClientLogin . I had no problem with this to work.

+1
source share

All Articles