Skip to content

Instantly share code, notes, and snippets.

@arslnb
Last active May 18, 2016 06:27
Show Gist options
  • Save arslnb/344ccc801a16f651cedb90ee40b57a33 to your computer and use it in GitHub Desktop.
Save arslnb/344ccc801a16f651cedb90ee40b57a33 to your computer and use it in GitHub Desktop.
import webbrowser
from oauth2client import client
client_id_file = "client_id.json"
flow = client.flow_from_clientsecrets(client_id_file, scope='https://www.googleapis.com/auth/analytics.readonly', redirect_uri='urn:ietf:wg:oauth:2.0:oob')
auth_uri = flow.step1_get_authorize_url()
# Open a browser window to manually authenticate and get the auth code
webbrowser.open(auth_uri)
auth_code = raw_input('Enter the authorization code: ')
credentials = flow.step2_exchange(auth_code)
# You can view various protected resources within the credentials object
# read http://oauth2client.readthedocs.io/en/latest/source/oauth2client.client.html#oauth2client.client.OAuth2Credentials
print credentials
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment