Skip to content

Commit 1dcc702

Browse files
added classroom snippets for managing new and exisitng aliases
1 parent c261986 commit 1dcc702

3 files changed

Lines changed: 79 additions & 1 deletion

File tree

calendar/quickstart/quickstart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def main():
3030
# created automatically when the authorization flow completes for the first
3131
# time.
3232
store = file.Storage('token.json')
33-
creds = store.get()
33+
creds = None
3434
if not creds or creds.invalid:
3535
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
3636
creds = tools.run_flow(flow, store)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from __future__ import print_function
2+
from googleapiclient.discovery import build
3+
from httplib2 import Http
4+
from oauth2client import file, client, tools
5+
6+
# If modifying these scopes, delete the file token.json.
7+
SCOPES = 'https://www.googleapis.com/auth/classroom.courses'
8+
9+
def main():
10+
"""Shows basic usage of the Classroom API.
11+
Prints the names of the first 10 courses the user has access to.
12+
"""
13+
# The file token.json stores the user's access and refresh tokens, and is
14+
# created automatically when the authorization flow completes for the first
15+
# time.
16+
store = file.Storage('token.json')
17+
print(store)
18+
creds = None
19+
if not creds or creds.invalid:
20+
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
21+
creds = tools.run_flow(flow, store)
22+
# [START classroom_quickstart]
23+
service = build('classroom', 'v1', http=creds.authorize(Http()))
24+
25+
alias = 'd:school_math_101'
26+
course = {
27+
'id': alias,
28+
'name': 'Math 101',
29+
'section': 'Period 2',
30+
'description': 'Course Description',
31+
'room': '301',
32+
'ownerId': 'teacherId'
33+
}
34+
try:
35+
course = service.courses().create(
36+
body=course).execute()
37+
except:
38+
print('Course Creation Failed')
39+
# Handle error
40+
# [END classroom_quickstart
41+
42+
if __name__ == '__main__':
43+
main()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from __future__ import print_function
2+
from googleapiclient.discovery import build
3+
from httplib2 import Http
4+
from oauth2client import file, client, tools
5+
6+
# If modifying these scopes, delete the file token.json.
7+
SCOPES = 'https://www.googleapis.com/auth/classroom.courses'
8+
9+
def main():
10+
"""Shows basic usage of the Classroom API.
11+
Prints the names of the first 10 courses the user has access to.
12+
"""
13+
# The file token.json stores the user's access and refresh tokens, and is
14+
# created automatically when the authorization flow completes for the first
15+
# time.
16+
store = file.Storage('token.json')
17+
print(store)
18+
creds = None
19+
if not creds or creds.invalid:
20+
flow = client.flow_from_clientsecrets('credentials.json', SCOPES)
21+
creds = tools.run_flow(flow, store)
22+
# [START classroom_quickstart]
23+
service = build('classroom', 'v1', http=creds.authorize(Http()))
24+
classroomCourseId = '123456'
25+
alias = 'd:school_math_101'
26+
courseAlias = {
27+
'alias': alias
28+
}
29+
courseAlias = service.courses().aliases().create(
30+
courseId=classroomCourseId,
31+
body=courseAlias).execute()
32+
# [END classroom_quickstart
33+
34+
if __name__ == '__main__':
35+
main()

0 commit comments

Comments
 (0)