Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion admin_sdk/directory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Directory API.
## Install

```
pip install --upgrade google-api-python-client oauth2client
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib pickle
```

## Run
Expand Down
33 changes: 23 additions & 10 deletions admin_sdk/directory/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,39 @@

# [START admin_sdk_directory_quickstart]
from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

# If modifying these scopes, delete the file token.json.
# If modifying these scopes, delete the file token.pickle.
SCOPES = 'https://www.googleapis.com/auth/admin.directory.user'

def main():
"""Shows basic usage of the Admin SDK Directory API.
Prints the emails and names of the first 10 users in the domain.
"""
# The file token.json stores the user's access and refresh tokens, and is
creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('admin', 'directory_v1', http=creds.authorize(Http()))
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server()
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)

service = build('admin', 'directory_v1', credentials=creds)

# Call the Admin SDK Directory API
print('Getting the first 10 users in the domain')
Expand Down
2 changes: 1 addition & 1 deletion admin_sdk/reports/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ that makes requests to the Google Admin SDK Reports API.
## Install

```
pip install --upgrade google-api-python-client oauth2client
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib pickle
```

## Run
Expand Down
33 changes: 23 additions & 10 deletions admin_sdk/reports/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,39 @@

# [START admin_sdk_reports_quickstart]
from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

# If modifying these scopes, delete the file token.json.
# If modifying these scopes, delete the file token.pickle.
SCOPES = 'https://www.googleapis.com/auth/admin.reports.audit.readonly'

def main():
"""Shows basic usage of the Admin SDK Reports API.
Prints the time, email, and name of the last 10 login events in the domain.
"""
# The file token.json stores the user's access and refresh tokens, and is
creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('admin', 'reports_v1', http=creds.authorize(Http()))
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server()
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)

service = build('admin', 'reports_v1', credentials=creds)

# Call the Admin SDK Reports API
print('Getting the last 10 login events')
Expand Down
2 changes: 1 addition & 1 deletion admin_sdk/reseller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ that makes requests to the Google Admin SDK Reseller API.
## Install

```
pip install --upgrade google-api-python-client oauth2client
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib pickle
```

## Run
Expand Down
33 changes: 23 additions & 10 deletions admin_sdk/reseller/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,39 @@

# [START admin_sdk_reseller_quickstart]
from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

# If modifying these scopes, delete the file token.json.
# If modifying these scopes, delete the file token.pickle.
SCOPES = 'https://www.googleapis.com/auth/apps.order'

def main():
"""Calls the Admin SDK Reseller API. Prints the customer ID, SKU ID,
and plan name of the first 10 subscriptions managed by the domain.
"""
# The file token.json stores the user's access and refresh tokens, and is
creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('reseller', 'v1', http=creds.authorize(Http()))
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server()
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)

service = build('reseller', 'v1', credentials=creds)

# Call the Admin SDK Reseller API
print('Getting the first 10 subscriptions')
Expand Down
2 changes: 1 addition & 1 deletion apps_script/quickstart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ that makes requests to the Google Apps Script API.
## Install

```
pip install --upgrade google-api-python-client oauth2client
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib pickle
```

## Run
Expand Down
33 changes: 23 additions & 10 deletions apps_script/quickstart/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
project, and log the script's URL to the user.
"""
from __future__ import print_function
import pickle
import os.path
from googleapiclient import errors
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

# If modifying these scopes, delete the file token.json.
# If modifying these scopes, delete the file token.pickle.
SCOPES = 'https://www.googleapis.com/auth/script.projects'

SAMPLE_CODE = '''
Expand All @@ -43,15 +45,26 @@
def main():
"""Calls the Apps Script API.
"""
# The file token.json stores the user's access and refresh tokens, and is
creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('script', 'v1', http=creds.authorize(Http()))
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server()
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)

service = build('script', 'v1', credentials=creds)

# Call the Apps Script API
try:
Expand Down
2 changes: 1 addition & 1 deletion calendar/quickstart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ makes requests to the Google Calendar API.
## Install

```
pip install --upgrade google-api-python-client oauth2client
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib pickle
```

## Run
Expand Down
33 changes: 23 additions & 10 deletions calendar/quickstart/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,39 @@
# [START calendar_quickstart]
from __future__ import print_function
import datetime
import pickle
import os.path
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

# If modifying these scopes, delete the file token.json.
# If modifying these scopes, delete the file token.pickle.
SCOPES = 'https://www.googleapis.com/auth/calendar.readonly'

def main():
"""Shows basic usage of the Google Calendar API.
Prints the start and name of the next 10 events on the user's calendar.
"""
# The file token.json stores the user's access and refresh tokens, and is
creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('calendar', 'v3', http=creds.authorize(Http()))
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server()
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)

service = build('calendar', 'v3', credentials=creds)

# Call the Calendar API
now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time
Expand Down
2 changes: 1 addition & 1 deletion classroom/quickstart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ makes requests to the Google Classroom API.
## Install

```
pip install --upgrade google-api-python-client oauth2client
pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib pickle
```

## Run
Expand Down
33 changes: 23 additions & 10 deletions classroom/quickstart/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,39 @@

# [START classroom_quickstart]
from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

# If modifying these scopes, delete the file token.json.
# If modifying these scopes, delete the file token.pickle.
SCOPES = 'https://www.googleapis.com/auth/classroom.courses.readonly'

def main():
"""Shows basic usage of the Classroom API.
Prints the names of the first 10 courses the user has access to.
"""
# The file token.json stores the user's access and refresh tokens, and is
creds = None
# The file token.pickle stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
store = file.Storage('token.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('classroom', 'v1', http=creds.authorize(Http()))
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server()
# Save the credentials for the next run
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)

service = build('classroom', 'v1', credentials=creds)

# Call the Classroom API
results = service.courses().list(pageSize=10).execute()
Expand Down
Loading