Skip to content

Commit 2c871ce

Browse files
author
Eric Koleda
authored
Merge pull request googleworkspace#15 from gsuitedevs/credentials
Change the file names expected for developer credentials
2 parents e2c7893 + 9c7bef4 commit 2c871ce

15 files changed

Lines changed: 56 additions & 104 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ client_secret.json
33
application_credentials.json
44
storage.json
55
credentials.json
6+
token.json
67

78
.DS_Store
89

admin_sdk/directory/quickstart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424

2525
# Setup the Admin SDK Directory API
2626
SCOPES = 'https://www.googleapis.com/auth/admin.directory.user'
27-
store = file.Storage('credentials.json')
27+
store = file.Storage('token.json')
2828
creds = store.get()
2929
if not creds or creds.invalid:
30-
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
30+
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
3131
creds = tools.run_flow(flow, store)
3232
service = build('admin', 'directory_v1', http=creds.authorize(Http()))
3333

admin_sdk/reports/quickstart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030

3131
# Setup the Admin SDK Reports API
3232
SCOPES = 'https://www.googleapis.com/auth/admin.reports.audit.readonly'
33-
store = file.Storage('credentials.json')
33+
store = file.Storage('token.json')
3434
creds = store.get()
3535
if not creds or creds.invalid:
36-
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
36+
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
3737
creds = tools.run_flow(flow, store)
3838
service = build('admin', 'reports_v1', http=creds.authorize(Http()))
3939

admin_sdk/reseller/quickstart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030

3131
# Setup the Admin SDK Reports API
3232
SCOPES = 'https://www.googleapis.com/auth/admin.reports.audit.readonly'
33-
store = file.Storage('credentials.json')
33+
store = file.Storage('token.json')
3434
creds = store.get()
3535
if not creds or creds.invalid:
36-
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
36+
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
3737
creds = tools.run_flow(flow, store)
3838
service = build('admin', 'reports_v1', http=creds.authorize(Http()))
3939

apps_script/quickstart/quickstart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
# Setup the Apps Script API
2727
SCOPES = 'https://www.googleapis.com/auth/script.projects'
28-
store = file.Storage('credentials.json')
28+
store = file.Storage('token.json')
2929
creds = store.get()
3030
if not creds or creds.invalid:
31-
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
31+
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
3232
creds = tools.run_flow(flow, store)
3333
service = build('script', 'v1', http=creds.authorize(Http()))
3434

calendar/quickstart/quickstart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
# Setup the Calendar API
2727
SCOPES = 'https://www.googleapis.com/auth/calendar.readonly'
28-
store = file.Storage('credentials.json')
28+
store = file.Storage('token.json')
2929
creds = store.get()
3030
if not creds or creds.invalid:
31-
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
31+
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
3232
creds = tools.run_flow(flow, store)
3333
service = build('calendar', 'v3', http=creds.authorize(Http()))
3434

classroom/quickstart/quickstart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626

2727
# Setup the Classroom API
2828
SCOPES = 'https://www.googleapis.com/auth/classroom.courses.readonly'
29-
store = file.Storage('credentials.json')
29+
store = file.Storage('token.json')
3030
creds = store.get()
3131
if not creds or creds.invalid:
32-
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
32+
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
3333
creds = tools.run_flow(flow, store)
3434
service = build('classroom', 'v1', http=creds.authorize(Http()))
3535

drive/activity/quickstart.py

Lines changed: 29 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -14,85 +14,36 @@
1414

1515
# [START drive_activity_quickstart]
1616
from __future__ import print_function
17-
import httplib2
18-
import os
19-
20-
from apiclient import discovery
21-
from oauth2client import client
22-
from oauth2client import tools
23-
from oauth2client.file import Storage
24-
17+
from apiclient.discovery import build
18+
from httplib2 import Http
19+
from oauth2client import file, client, tools
2520
import datetime
2621

27-
try:
28-
import argparse
29-
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
30-
except ImportError:
31-
flags = None
32-
33-
# If modifying these scopes, delete your previously saved credentials
34-
# at ~/.credentials/appsactivity-python-quickstart.json
22+
# Setup the Drive Activity API
3523
SCOPES = 'https://www.googleapis.com/auth/activity https://www.googleapis.com/auth/drive.metadata.readonly'
36-
CLIENT_SECRET_FILE = 'client_secret.json'
37-
APPLICATION_NAME = 'G Suite Activity API Python Quickstart'
38-
39-
40-
def get_credentials():
41-
"""Gets valid user credentials from storage.
42-
43-
If nothing has been stored, or if the stored credentials are invalid,
44-
the OAuth2 flow is completed to obtain the new credentials.
45-
46-
Returns:
47-
Credentials, the obtained credential.
48-
"""
49-
home_dir = os.path.expanduser('~')
50-
credential_dir = os.path.join(home_dir, '.credentials')
51-
if not os.path.exists(credential_dir):
52-
os.makedirs(credential_dir)
53-
credential_path = os.path.join(credential_dir,
54-
'appsactivity-python-quickstart.json')
55-
56-
store = Storage(credential_path)
57-
credentials = store.get()
58-
if not credentials or credentials.invalid:
59-
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
60-
flow.user_agent = APPLICATION_NAME
61-
if flags:
62-
credentials = tools.run_flow(flow, store, flags)
63-
else: # Needed only for compatibility with Python 2.6
64-
credentials = tools.run(flow, store)
65-
print('Storing credentials to ' + credential_path)
66-
return credentials
67-
68-
def main():
69-
"""Shows basic usage of the G Suite Activity API.
70-
71-
Creates a G Suite Activity API service object and
72-
outputs the recent activity in your Google Drive.
73-
"""
74-
credentials = get_credentials()
75-
http = credentials.authorize(httplib2.Http())
76-
service = discovery.build('appsactivity', 'v1', http=http)
77-
78-
results = service.activities().list(source='drive.google.com',
79-
drive_ancestorId='root', pageSize=10).execute()
80-
activities = results.get('activities', [])
81-
if not activities:
82-
print('No activity.')
83-
else:
84-
print('Recent activity:')
85-
for activity in activities:
86-
event = activity['combinedEvent']
87-
user = event.get('user', None)
88-
target = event.get('target', None)
89-
if user == None or target == None:
90-
continue
91-
time = datetime.datetime.fromtimestamp(
92-
int(event['eventTimeMillis'])/1000)
93-
print('{0}: {1}, {2}, {3} ({4})'.format(time, user['name'],
94-
event['primaryEventType'], target['name'], target['mimeType']))
95-
96-
if __name__ == '__main__':
97-
main()
24+
store = file.Storage('token.json')
25+
creds = store.get()
26+
if not creds or creds.invalid:
27+
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
28+
creds = tools.run_flow(flow, store)
29+
service = build('appsactivity', 'v1', http=creds.authorize(Http()))
30+
31+
# Call the Drive Activity API
32+
results = service.activities().list(source='drive.google.com',
33+
drive_ancestorId='root', pageSize=10).execute()
34+
activities = results.get('activities', [])
35+
if not activities:
36+
print('No activity.')
37+
else:
38+
print('Recent activity:')
39+
for activity in activities:
40+
event = activity['combinedEvent']
41+
user = event.get('user', None)
42+
target = event.get('target', None)
43+
if user == None or target == None:
44+
continue
45+
time = datetime.datetime.fromtimestamp(
46+
int(event['eventTimeMillis'])/1000)
47+
print('{0}: {1}, {2}, {3} ({4})'.format(time, user['name'],
48+
event['primaryEventType'], target['name'], target['mimeType']))
9849
# [END drive_activity_quickstart]

drive/quickstart/quickstart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626

2727
# Setup the Drive v3 API
2828
SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly'
29-
store = file.Storage('credentials.json')
29+
store = file.Storage('token.json')
3030
creds = store.get()
3131
if not creds or creds.invalid:
32-
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
32+
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
3333
creds = tools.run_flow(flow, store)
3434
service = build('drive', 'v3', http=creds.authorize(Http()))
3535

gmail/quickstart/quickstart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
# Setup the Gmail API
2727
SCOPES = 'https://www.googleapis.com/auth/gmail.readonly'
28-
store = file.Storage('credentials.json')
28+
store = file.Storage('token.json')
2929
creds = store.get()
3030
if not creds or creds.invalid:
31-
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
31+
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
3232
creds = tools.run_flow(flow, store)
3333
service = build('gmail', 'v1', http=creds.authorize(Http()))
3434

0 commit comments

Comments
 (0)