The Google Contacts API cannot be used with the google-api-python-client library, since it is a Google data API , and google-api-python-client intended to be used with the discovery-based API .
Instead of overcoming all the problems described by @NikolayFominyh , you can use the built-in OAuth 2.0 support in gdata-python-client .
To get a valid token, follow the instructions in the Google Blog Report for a detailed description of the process.
First create a token object:
import gdata.gauth CLIENT_ID = 'bogus.id'
Then authorize your application using this token:
APPLICATION_REDIRECT_URI = 'http://www.example.com/oauth2callback' authorize_url = auth_token.generate_authorize_url( redirect_uri=APPLICATION_REDIRECT_URI)
After creating this authorize_url you (or users of your application) will need to visit it and accept the OAuth 2.0 invitation. If it is in a web application, you can simply redirect, otherwise you will need to visit the link in the browser.
After authorization, replace the code for the token:
import atom.http_core redirect_url = 'http://www.example.com/oauth2callback?code=SOME-RETURNED-VALUE' url = atom.http_core.ParseUri(redirect_url) auth_token.get_access_token(url.query)
In case you visited the browser, you need to copy the URL to which you are redirected to the redirect_url variable.
In case you are in a web application, you can specify a handler for the /oauth2callback (for example) and you can just get the code request parameter to exchange the code for the token. For example, if you use WebOb :
redirect_url = atom.http_core.Uri.parse_uri(self.request.uri)
Finally, authorize your client using this token:
import gdata.contacts.service client = gdata.contacts.service.ContactsService(source='appname') auth_token.authorize(client)
Update (12 months after the initial response):
Alternatively, you can use google-api-python-client support, as I described in the post.
bossylobster
source share