Skip to content

Commit 2657954

Browse files
committed
Add rest of python quickstarts
1 parent 6ce7748 commit 2657954

File tree

27 files changed

+628
-37
lines changed

27 files changed

+628
-37
lines changed

README.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,49 @@
11
# G Suite Python Samples
22

3-
## Calendar
3+
Python samples for [G Suite API](https://developers.google.com/gsuite/) docs.
4+
5+
## APIs
6+
7+
### Admin SDK
8+
9+
- [Directory Quickstart](https://developers.google.com/admin-sdk/directory/v1/quickstart/python)
10+
- [Group Migration Quickstart](https://developers.google.com/admin-sdk/groups-migration/v1/quickstart/python)
11+
- [Group Settings Quickstart](https://developers.google.com/admin-sdk/groups-settings/quickstart/python)
12+
- [Licensing Quickstart](https://developers.google.com/admin-sdk/licensing/v1/quickstart/python)
13+
- [Reports Quickstart](https://developers.google.com/admin-sdk/reports/v1/quickstart/python)
14+
- [Reseller Quickstart](https://developers.google.com/admin-sdk/reseller/v1/quickstart/python)
15+
16+
### Apps Script
17+
18+
- [Quickstart](https://developers.google.com/apps-script/api/quickstart/python)
19+
20+
### Calendar
421

522
- [Quickstart](https://developers.google.com/google-apps/calendar/quickstart/python)
623

7-
## Drive
24+
### Classroom
25+
26+
- [Quickstart](https://developers.google.com/classroom/quickstart/python)
27+
28+
### Drive V3
829

930
- [Quickstart](https://developers.google.com/drive/v3/web/quickstart/python)
31+
- [DriveApp](drive/driveapp): A simple app that uploads a file to Google Drive.
1032

11-
## Gmail
33+
### Gmail
1234

1335
- [Quickstart](https://developers.google.com/gmail/api/quickstart/python)
1436

15-
## Sheets
37+
### Sheets
1638

1739
- [Quickstart](https://developers.google.com/sheets/api/quickstart/python)
40+
- [Snippets](https://developers.google.com/sheets/api/guides/concepts)
1841

19-
## Slides
42+
### Slides
2043

2144
- [Quickstart](https://developers.google.com/slides/quickstart/python)
45+
- [Snippets](https://developers.google.com/slides/how-tos/overview)
46+
47+
### Tasks
48+
49+
- [Quickstart](https://developers.google.com/google-apps/tasks/quickstart/python)

admin_sdk/directory/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Google Admin SDK Directory Python Quickstart
2+
3+
Complete the steps described in the [Google Admin SDK Directory Python
4+
Quickstart](https://developers.google.com/google-apps/Admin SDK
5+
Directory/quickstart/python), and in about five minutes you'll have a simple
6+
Python command-line application that makes requests to the Google Admin SDK
7+
Directory API.
8+
9+
## Install
10+
11+
```
12+
pip install --upgrade google-api-python-client
13+
```
14+
15+
## Run
16+
17+
```
18+
python quickstart.py
19+
```

admin_sdk/directory/quickstart.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START admin_sdk_directory_quickstart]
16+
"""
17+
Shows basic usage of the Admin SDK Directory API. Lists of first 10 users in the
18+
domain.
19+
"""
20+
from __future__ import print_function
21+
from apiclient.discovery import build
22+
from httplib2 import Http
23+
from oauth2client import file, client, tools
24+
25+
# Setup the Admin SDK Directory API
26+
SCOPES = 'https://www.googleapis.com/auth/admin.directory.user'
27+
store = file.Storage('credentials.json')
28+
creds = store.get()
29+
if not creds or creds.invalid:
30+
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
31+
creds = tools.run_flow(flow, store)
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+
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]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Google Admin SDK Groups Migration Python Quickstart
2+
3+
Complete the steps described in the [Google Admin SDK Groups Migration Python
4+
Quickstart](https://developers.google.com/admin-sdk/groups-migration/v1/quickstart/python),
5+
and in about five minutes you'll have a simple Python command-line application
6+
that makes requests to the Google Admin SDK Groups Migration API.
7+
8+
## Install
9+
10+
```
11+
pip install --upgrade google-api-python-client
12+
```
13+
14+
## Run
15+
16+
```
17+
python quickstart.py
18+
```
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START admin_sdk_groups_migration_quickstart]
16+
"""
17+
Shows basic usage of the Admin SDK Groups Migration API. Inserts a test email
18+
into a group.
19+
"""
20+
from __future__ import print_function
21+
from apiclient.discovery import build, http
22+
from httplib2 import Http
23+
from oauth2client import file, client, tools
24+
import StringIO
25+
import random
26+
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.migration'
33+
store = file.Storage('credentials.json')
34+
creds = store.get()
35+
if not creds or creds.invalid:
36+
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
37+
creds = tools.run_flow(flow, store)
38+
service = build('groupsmigration', 'v1', http=creds.authorize(Http()))
39+
40+
# Call the Admin SDK Groups Migration API
41+
print('Warning: A test email will be inserted into the group entered.')
42+
groupId = raw_input(
43+
'Enter the email address of a Google Group in your domain: ')
44+
45+
# Format an RFC822 message
46+
message = MIMEText.MIMEText('This is a test.')
47+
# Generate a random 10 digit number for message Id.
48+
message['Message-ID'] = '<{0}-{1}>'.format(str(random.randrange(10**10)),
49+
groupId)
50+
message['Subject'] = 'Groups Migration API Test (Python)'
51+
message['From'] = '"Alice Smith" <alice@example.com>'
52+
message['To'] = groupId
53+
message['Date'] = Utils.formatdate(localtime=True)
54+
55+
stream = StringIO.StringIO()
56+
stream.write(message.as_string())
57+
media = apiclient.http.MediaIoBaseUpload(stream,
58+
mimetype='message/rfc822')
59+
60+
result = service.archive().insert(groupId=groupId,
61+
media_body=media).execute()
62+
print(result['responseCode'])
63+
# [END admin_sdk_groups_migration_quickstart]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Google Admin SDK Groups Settings Python Quickstart
2+
3+
Complete the steps described in the [Google Admin SDK Groups Settings Python
4+
Quickstart](https://developers.google.com/admin-sdk/groups-settings/quickstart/python),
5+
and in about five minutes you'll have a simple Python command-line application
6+
that makes requests to the Google Admin SDK Groups Settings API.
7+
8+
## Install
9+
10+
```
11+
pip install --upgrade google-api-python-client
12+
```
13+
14+
## Run
15+
16+
```
17+
python quickstart.py
18+
```
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START admin_sdk_groups_migration_quickstart]
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.
19+
"""
20+
from __future__ import print_function
21+
from apiclient.discovery import build, http
22+
from httplib2 import Http
23+
from oauth2client import file, client, tools
24+
import StringIO
25+
import random
26+
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'
33+
store = file.Storage('credentials.json')
34+
creds = store.get()
35+
if not creds or creds.invalid:
36+
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
37+
creds = tools.run_flow(flow, store)
38+
service = build('groupssettings', 'v1', http=creds.authorize(Http()))
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_migration_quickstart]

admin_sdk/licensing/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Google Admin SDK Licensing Python Quickstart
2+
3+
Complete the steps described in the [Google Admin SDK Licensing Python
4+
Quickstart](https://developers.google.com/admin-sdk/licensing/v1/quickstart/python),
5+
and in about five minutes you'll have a simple Python command-line application
6+
that makes requests to the Google Admin SDK Licensing API.
7+
8+
## Install
9+
10+
```
11+
pip install --upgrade google-api-python-client
12+
```
13+
14+
## Run
15+
16+
```
17+
python quickstart.py
18+
```

admin_sdk/licensing/quickstart.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START admin_sdk_licensing_quickstart]
16+
"""
17+
Shows basic usage of the Admin SDK Licensing API. Outputs the first 10 license
18+
assignments for G Suite seats.
19+
"""
20+
from __future__ import print_function
21+
from apiclient.discovery import build, http
22+
from httplib2 import Http
23+
from oauth2client import file, client, tools
24+
import StringIO
25+
import random
26+
27+
import apiclient
28+
from email import Utils
29+
from email import MIMEText
30+
31+
# Setup the Admin SDK Licensing API
32+
SCOPES = 'https://www.googleapis.com/auth/apps.licensing'
33+
store = file.Storage('credentials.json')
34+
creds = store.get()
35+
if not creds or creds.invalid:
36+
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
37+
creds = tools.run_flow(flow, store)
38+
service = build('licensing', 'v1', http=creds.authorize(Http()))
39+
40+
customerId = raw_input('Enter the domain name of your G Suite domain: ')
41+
results = service.licenseAssignments().listForProduct(
42+
productId='Google-Apps', customerId=customerId, maxResults=10).execute()
43+
items = results.get('items', [])
44+
if not items:
45+
print('No license assignments found.')
46+
else:
47+
print('License assignments:')
48+
for item in items:
49+
print('{0} ({1})'.format(item['userId'], item['skuId']))
50+
# [END admin_sdk_licensing_quickstart]

admin_sdk/reports/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Google Admin SDK Reports Python Quickstart
2+
3+
Complete the steps described in the [Google Admin SDK Reports Python
4+
Quickstart](https://developers.google.com/admin-sdk/reports/v1/quickstart/python),
5+
and in about five minutes you'll have a simple Python command-line application
6+
that makes requests to the Google Admin SDK Reports API.
7+
8+
## Install
9+
10+
```
11+
pip install --upgrade google-api-python-client
12+
```
13+
14+
## Run
15+
16+
```
17+
python quickstart.py
18+
```

0 commit comments

Comments
 (0)