Skip to content

Instantly share code, notes, and snippets.

@ojarva
Created May 12, 2014 10:56
Show Gist options
  • Save ojarva/41ea01cf5c4302234a91 to your computer and use it in GitHub Desktop.
Save ojarva/41ea01cf5c4302234a91 to your computer and use it in GitHub Desktop.
from oauth2client.client import flow_from_clientsecrets
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.file import Storage
storage = Storage('a_credentials_file')
credentials = storage.get()
if not credentials:
flow = flow_from_clientsecrets('client_secrets.json',
scope='https://www.googleapis.com/auth/admin.reports.audit.readonly',
redirect_uri='urn:ietf:wg:oauth:2.0:oob')
auth_uri = flow.step1_get_authorize_url()
print auth_uri
code = raw_input("Auth token: ")
credentials = flow.step2_exchange(code)
storage.put(credentials)
http = httplib2.Http()
http = credentials.authorize(http)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment