|
14 | 14 |
|
15 | 15 | # [START admin_sdk_reseller_quickstart] |
16 | 16 | """ |
17 | | -Shows basic usage of the Admin SDK Reports API. Outputs a list of last 10 login |
18 | | -events. |
| 17 | +Shows basic usage of the Admin SDK Reseller API. Prints the customer ID, SKU ID, |
| 18 | +and plan name of the first 10 subscriptions managed by the domain. |
19 | 19 | """ |
20 | 20 | from __future__ import print_function |
21 | 21 | from apiclient.discovery import build |
22 | 22 | from httplib2 import Http |
23 | 23 | from oauth2client import file, client, tools |
24 | 24 |
|
25 | 25 | # If modifying these scopes, delete the file token.json. |
26 | | -SCOPES = 'https://www.googleapis.com/auth/admin.reports.audit.readonly' |
| 26 | +SCOPES = 'https://www.googleapis.com/auth/apps.order' |
27 | 27 |
|
28 | 28 |
|
29 | 29 | def main(): |
30 | | - """Runs the sample. |
| 30 | + """Calls the Admin SDK Reseller API. |
31 | 31 | """ |
32 | 32 | store = file.Storage('token.json') |
33 | 33 | creds = store.get() |
34 | 34 | if not creds or creds.invalid: |
35 | 35 | flow = client.flow_from_clientsecrets('credentials.json', SCOPES) |
36 | 36 | creds = tools.run_flow(flow, store) |
37 | | - service = build('admin', 'reports_v1', http=creds.authorize(Http())) |
| 37 | + service = build('reseller', 'v1', http=creds.authorize(Http())) |
38 | 38 |
|
39 | | - print('Getting the last 10 login events') |
40 | | - results = service.activities().list(userKey='all', applicationName='login', |
41 | | - maxResults=10).execute() |
42 | | - activities = results.get('items', []) |
| 39 | + print('Getting the first 10 subscriptions') |
| 40 | + results = service.subscriptions().list(maxResults=10).execute() |
| 41 | + subscriptions = results.get('subscriptions', []) |
43 | 42 |
|
44 | | - if not activities: |
45 | | - print('No logins found.') |
| 43 | + if not subscriptions: |
| 44 | + print('No subscriptions found.') |
46 | 45 | else: |
47 | | - print('Logins:') |
48 | | - for activity in activities: |
49 | | - print(u'{0}: {1} ({2})'.format(activity['id']['time'], |
50 | | - activity['actor']['email'], |
51 | | - activity['events'][0]['name'])) |
| 46 | + print('Subscriptions:') |
| 47 | + for subscription in subscriptions: |
| 48 | + print(u'{0} ({1}, {2})'.format(subscription['customerId'], |
| 49 | + subscription['skuId'], |
| 50 | + subscription['plan']['planName'])) |
52 | 51 |
|
53 | 52 |
|
54 | 53 | if __name__ == '__main__': |
|
0 commit comments