Created
May 30, 2014 06:49
-
-
Save madhavan-rp/1e45415fcd1ec452b990 to your computer and use it in GitHub Desktop.
Simple script that prints a given google contact in JSON
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
client_id = r'<Client ID>' | |
client_secret = r'<Client Secret>' | |
redirect_uri = 'https://localhost:5000/authorized' | |
scope = ['https://www.googleapis.com/auth/userinfo.email', | |
'https://www.googleapis.com/auth/userinfo.profile', | |
'https://www.google.com/m8/feeds', | |
'https://mail.google.com/' | |
] | |
from requests_oauthlib import OAuth2Session | |
import requests | |
google = OAuth2Session(client_id, redirect_uri=redirect_uri, | |
scope=scope) | |
refresh = { | |
'client_secret':client_secret, | |
'client_id': client_id, | |
'grant_type':'refresh_token' | |
} | |
refresh['refresh_token'] = r'<Refresh Token>' | |
r = requests.post('https://accounts.google.com/o/oauth2/token',data=refresh) | |
print r.json()['access_token'] | |
params = { | |
'access_token':r.json()['access_token'], | |
'alt':'json' | |
} | |
headers = { | |
'GData-Version': 3.0 | |
} | |
r = requests.get('https://www.google.com/m8/feeds/contacts/default/full/<Contact ID>', params=params, headers=headers) | |
from pprint import pprint | |
pprint(r.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment