|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -# [START admin_sdk_groups_settings_quickstart] |
| 15 | +# [START admin_sdk_directory_quickstart] |
16 | 16 | """ |
17 | | -Shows basic usage of the Admin SDK Groups Settings API. Outputs a group's |
18 | | -settings identified by the group's email address. |
| 17 | +Shows basic usage of the Admin SDK Directory API. Lists of first 10 users in the |
| 18 | +domain. |
19 | 19 | """ |
20 | 20 | from __future__ import print_function |
21 | | -from apiclient.discovery import build, http |
| 21 | +from apiclient.discovery import build |
22 | 22 | from httplib2 import Http |
23 | 23 | from oauth2client import file, client, tools |
24 | | -import StringIO |
25 | | -import random |
26 | 24 |
|
27 | | -import apiclient |
28 | | -from email import Utils |
29 | | -from email import MIMEText |
30 | | - |
31 | | -# Setup the Admin SDK Groups Migration API |
32 | | -SCOPES = 'https://www.googleapis.com/auth/apps.groups.settings' |
| 25 | +# Setup the Admin SDK Directory API |
| 26 | +SCOPES = 'https://www.googleapis.com/auth/admin.directory.user' |
33 | 27 | store = file.Storage('credentials.json') |
34 | 28 | creds = store.get() |
35 | 29 | if not creds or creds.invalid: |
36 | 30 | flow = client.flow_from_clientsecrets('client_secret.json', SCOPES) |
37 | 31 | creds = tools.run_flow(flow, store) |
38 | | -service = build('groupssettings', 'v1', http=creds.authorize(Http())) |
| 32 | +service = build('admin', 'directory_v1', http=creds.authorize(Http())) |
| 33 | + |
| 34 | +# Call the Admin SDK Directory API |
| 35 | +print('Getting the first 10 users in the domain') |
| 36 | +results = service.users().list(customer='my_customer', maxResults=10, |
| 37 | + orderBy='email').execute() |
| 38 | +users = results.get('users', []) |
39 | 39 |
|
40 | | -groupEmail = raw_input('Enter the email address of a Google Group in your domain: ') |
41 | | -try: |
42 | | - results = service.groups().get(groupUniqueId=groupEmail, |
43 | | - alt='json').execute() |
44 | | - print(json.dumps(results, indent=4)) |
45 | | -except: |
46 | | - print('Unable to read group: {0}'.format(groupEmail)) |
47 | | - raise |
48 | | -# [END admin_sdk_groups_settings_quickstart] |
| 40 | +if not users: |
| 41 | + print('No users in the domain.') |
| 42 | +else: |
| 43 | + print('Users:') |
| 44 | + for user in users: |
| 45 | + print('{0} ({1})'.format(user['primaryEmail'], user['name']['fullName'])) |
| 46 | +# [END admin_sdk_directory_quickstart] |
0 commit comments