Skip to content

Instantly share code, notes, and snippets.

@jorilallo
Created September 9, 2012 19:33
Show Gist options
  • Save jorilallo/3686737 to your computer and use it in GitHub Desktop.
Save jorilallo/3686737 to your computer and use it in GitHub Desktop.
Google Contacts API authentication with gdata and OAuth2
import gdata
import json
import requests
# More examples:
# https://github.com/millioner/Python-contact-importer/blob/master/contact_importer/providers/google.py
# https://github.com/jtauber/django-friends/blob/master/friends/importer.py
# GData with access token
token = gdata.gauth.OAuth2Token(
client_id=GOOGLE_CLIENT_ID,
client_secret=GOOGLE_CLIENT_SECRET,
scope='https://www.google.com/m8/feeds',
user_agent='app.testing',
access_token=access_token)
contact_client = gdata.contacts.client.ContactsClient()
token.authorize(contact_client)
feed = contact_client.GetContacts()
for entry in feed.entry:
entry.title.text
for e in entry.email:
e.address
# JSON with access token
r = requests.get('https://www.google.com/m8/feeds/contacts/default/full?access_token=%s&alt=json&max-results=50&start-index=0' % (access_token))
data = json.loads(r.text)
@omerbn
Copy link

omerbn commented Sep 3, 2017

Thanks!

@bansal95
Copy link

Please tell me that how you get access token

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment