forked from salrashid123/gcpsamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserflow.py
42 lines (32 loc) · 1.36 KB
/
userflow.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
37
38
39
40
41
42
#!/usr/bin/python
import httplib2
from apiclient import discovery
import oauth2client
from apiclient.discovery import build
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
flow = flow_from_clientsecrets('client_secrets.json',
scope='https://www.googleapis.com/auth/userinfo.email',
redirect_uri='urn:ietf:wg:oauth:2.0:oob')
auth_uri = flow.step1_get_authorize_url()
print 'goto the following url ' + auth_uri
code = raw_input('Enter token:')
credentials = flow.step2_exchange(code)
http = credentials.authorize(httplib2.Http())
storage = Storage('user_creds.json')
storage.put(credentials)
service = build(serviceName='oauth2', version= 'v2',http=http)
resp = service.userinfo().get().execute()
print resp['email']
# -------------------------------------
#from google_auth_oauthlib.flow import InstalledAppFlow
#flow = InstalledAppFlow.from_client_secrets_file(
# 'client_secrets.json',
# scopes=['profile', 'email'])
#flow.run_local_server()
#client = photos_v1.PhotoServiceClient(credentials=flow.credentials)
# credentials = google.oauth2.credentials.Credentials.from_authorized_user_file('user_creds.json')
#client = storage.Client(credentials=credentials, project=project)
#buckets = client.list_buckets(project=project)
#for bucket in buckets:
# print bucket.name