|
19 | 19 | from oauth2client import file, client, tools |
20 | 20 | import datetime |
21 | 21 |
|
22 | | -# Setup the Drive Activity API |
23 | | -SCOPES = 'https://www.googleapis.com/auth/activity https://www.googleapis.com/auth/drive.metadata.readonly' |
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())) |
| 22 | +# If modifying these scopes, delete the file token.json. |
| 23 | +SCOPES = 'https://www.googleapis.com/auth/activity' |
30 | 24 |
|
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'])) |
| 25 | + |
| 26 | +def main(): |
| 27 | + """Runs the sample. |
| 28 | + """ |
| 29 | + store = file.Storage('token.json') |
| 30 | + creds = store.get() |
| 31 | + if not creds or creds.invalid: |
| 32 | + flow = client.flow_from_clientsecrets('credentials.json', SCOPES) |
| 33 | + creds = tools.run_flow(flow, store) |
| 34 | + service = build('appsactivity', 'v1', http=creds.authorize(Http())) |
| 35 | + |
| 36 | + # Call the Drive Activity API |
| 37 | + results = service.activities().list(source='drive.google.com', |
| 38 | + drive_ancestorId='root', |
| 39 | + pageSize=10).execute() |
| 40 | + activities = results.get('activities', []) |
| 41 | + if not activities: |
| 42 | + print('No activity.') |
| 43 | + else: |
| 44 | + print('Recent activity:') |
| 45 | + for activity in activities: |
| 46 | + event = activity['combinedEvent'] |
| 47 | + user = event.get('user', None) |
| 48 | + target = event.get('target', None) |
| 49 | + if user is None or target is None: |
| 50 | + continue |
| 51 | + time = datetime.datetime.fromtimestamp( |
| 52 | + int(event['eventTimeMillis'])/1000) |
| 53 | + print(u'{0}: {1}, {2}, {3} ({4})'.format(time, |
| 54 | + user['name'], |
| 55 | + event['primaryEventType'], |
| 56 | + target['name'], |
| 57 | + target['mimeType'])) |
| 58 | + |
| 59 | + |
| 60 | +if __name__ == '__main__': |
| 61 | + main() |
49 | 62 | # [END drive_activity_quickstart] |
0 commit comments