/
get_oauth2_token.py
36 lines (23 loc) · 1.08 KB
/
get_oauth2_token.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'''
This script will attempt to open your webbrowser,
perform OAuth 2 authentication and print your access token.
It depends on two libraries: oauth2client and gflags.
To install dependencies from PyPI:
$ pip install python-gflags oauth2client
Then run this script:
$ python get_oauth2_token.py
This is a combination of snippets from:
https://developers.google.com/api-client-library/python/guide/aaa_oauth
'''
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run
from oauth2client.file import Storage
CLIENT_ID = '1034260929149-kkss24182vvidbv5j23kj8om69u4ml0m.apps.googleusercontent.com'
CLIENT_SECRET = 'Dg3eiHJr7zk7F1u9CS'
flow = OAuth2WebServerFlow(client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
scope='https://spreadsheets.google.com/feeds https://docs.google.com/feeds',
redirect_uri='http://example.com/auth_return')
storage = Storage('creds.data')
credentials = run(flow, storage)
print "access_token: %s" % credentials.access_token