【发布时间】:2017-05-10 07:31:24
【问题描述】:
我有一个在 GAE (Python) 上运行的应用程序,Google 课堂用户可以在其中导入他/她的课程(学生姓名和名单)。代码分为两部分。首先,我得到该用户所有课程的列表:
directoryauthdecorator = OAuth2Decorator(
approval_prompt='force',
client_id='my_client_id',
client_secret='my_client_secret',
callback_path='/oauth2callback',
scope=[
'https://www.googleapis.com/auth/classroom.courses',
'https://www.googleapis.com/auth/classroom.rosters'])
class ClassroomAPI(webapp.RequestHandler):
@directoryauthdecorator.oauth_required
def get(self):
function=self.request.get('function')
auth_http = directoryauthdecorator.http()
service = build("classroom", "v1", http=auth_http)
if function == "getAllCourses":
try:
results = service.courses().list(pageSize=100,teacherId=users.get_current_user().email(),courseStates="ACTIVE").execute()
courses = results.get('courses',[])
#PARSE AND RETURN LIST OF COURSES TO USER
except errors.HttpError, error:
#RETURN ERROR
application = webapp.WSGIApplication(
[('/classroomAPI', ClassroomAPI),
(directoryauthdecorator.callback_path, directoryauthdecorator.callback_handler())],
debug=True)
这部分一直有效。然后用户从列表中选择他/她想要导入的课程。选择的课程回传到上面的脚本,执行下一部分:
if function == "getStudentListForCourse":
students=[]
selectedCourses = json.loads(self.request.body)["courses"]
for course in selectedCourses:
page_token=None
while True:
params={}
params["courseId"]=course["classroomId"]
params["pageSize"]=50
if page_token:
params["pageToken"]=page_token
studentList = service.courses().students().list(**params).execute()
for student in studentList['students']:
students.append(student['profile']['emailAddress'])
page_token = studentList.get('nextPageToken')
if not page_token:
break
#RETURN STUDENTS
这里的问题是我的日志在studentList = service.courses().students().list(**params).execute() 线上随机报告'DeadlineExceededError',这使得导入过程不可靠。
任何提示将不胜感激。
更新:
我已经尝试过 alpeware 发布的建议,但不幸的是它没有任何作用。
【问题讨论】:
标签: python google-app-engine google-classroom