Created
September 9, 2012 19:33
-
-
Save jorilallo/3686737 to your computer and use it in GitHub Desktop.
Google Contacts API authentication with gdata and OAuth2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please tell me that how you get access token