What possible ways to import google contacts using python and oauth2.0 exists?
We successfully got credentials, and our application requests access to contacts, but after getting credentials I can’t find way to discover contacts api.
So things like:
from apiclient.discover import build
import httplib2
http = httplib2.Http()
#Authorization
service = build("contacts", "v3", http=http)
Gives us UnknownApiNameOrVersion exception.
It looks like Contacts API not in list of supported APIs for apiclient.
I’m looking for alternative ways.
The Google Contacts API can’t be used with the
google-api-python-clientlibrary because it is a Google Data API, whilegoogle-api-python-clientis intended to be used with discovery-based APIs.Rather than going through all the trouble described by @NikolayFominyh, you can use the native support for OAuth 2.0 in
gdata-python-client.To get a valid token, follow the instructions from a Google Developers blog post for an in-depth description of the process.
First, create a token object:
Then, authorize your application with this token:
After generating this
authorize_url, you (or users of your application) will need to visit it and accept the OAuth 2.0 prompt. If this is within a web application, you can simply redirect, otherwise you’ll need to visit the link in a browser.After authorizing, exchange the code for a token:
In the case you visited a browser, you’ll need to copy the URL you were redirected to into the variable
redirect_url.In the case you are in a web application, you will be able to specify the handler for the path
/oauth2callback(for example) and simply can retrieve the query parametercodeto exchange the code for a token. For example, if usingWebOb:Finally authorize your client with this token:
Update (12+ months after original answer):
Alternately you can use the
google-api-python-clientsupport as I describe in a blog post.