我是一名高中老师,正在针对Google课堂撰写Google Apps脚本。我想创建一个电子表格,例如我的学生可以使用他们的证书访问我的学生成绩。
我已经成功编写了代码,以便我可以通过显式将学生的Id放在代码中来运行我的权限。另外,我已经成功地在Python 中编写了代码,我可以在这里明确设置学生需要访问这个(并且只有这个)信息的两个范围。但是,Google Apps Scripts自动范围生成让我受阻,因为我无法明确要求只提供我想要的两个范围。
以下是我在python中编写时使用的两个范围:
SCOPES = ['https://www.googleapis.com/auth/classroom.coursework.me.readonly https://www.googleapis.com/auth/classroom.student-submissions.me.readonly']
以下是Google Apps脚本自动生成的范围。
5 OAuth Scopes required by the script:
https://www.googleapis.com/auth/classroom.courses
https://www.googleapis.com/auth/classroom.coursework.students
https://www.googleapis.com/auth/classroom.profile.emails
https://www.googleapis.com/auth/classroom.profile.photos
https://www.googleapis.com/auth/classroom.rosters
这是我的代码:
function doGet() {
return HtmlService.createHtmlOutputFromFile('Index');
}
function getMyGrades() {
var pageToken;
var studentSubmissionsArray = [];
//Get Student Submissions for the logged in student that is running this app
do {
var optionalArgs = {
'pageToken': pageToken,
'userId' : 'me',
};
var response = Classroom.Courses.CourseWork.StudentSubmissions.list(courseId='7131560586', courseWorkId='-', optionalArgs);
var studentSubmissions = response.studentSubmissions;
if (studentSubmissions && studentSubmissions.length > 0) {
for (i = 0; i < studentSubmissions.length; i++) {
var studentSubmission = studentSubmissions[i];
var courseworkResponse = Classroom.Courses.CourseWork.get(courseId = '7131560586', id = studentSubmission.courseWorkId)
var studentSubmissionArray = [courseworkResponse.title, courseworkResponse.maxPoints];
studentSubmissionArray.push(studentSubmission.assignedGrade, studentSubmission.courseWorkType, studentSubmission.late, studentSubmission.state, studentSubmission.courseWorkId);
studentSubmissionsArray.push(studentSubmissionArray);
}
} else {
studentSubmissionsTable = "No Students Found";
}
pageToken = response.nextPageToken;
} while (pageToken);
studentSubmissionsArray.sort()
var studentSubmissionsTable = "<table border = 1, cellpadding = 8><tr><th>#</th><th>Title</th><th>Max Points</th><th>Assigned Grade</th><th>Type</th><th>late</th><th>State</th><th>Coursework ID</th></tr>"
if (studentSubmissionsArray && studentSubmissionsArray.length > 0) {
for (i = 0; i < studentSubmissionsArray.length; i++) {
c = i + 1;
studentSubmissionArray = studentSubmissionsArray[i];
studentSubmissionsTable = studentSubmissionsTable + '<tr><td>'+c+'</td><td>'+ studentSubmissionArray[0] + '</td><td>' + studentSubmissionArray[1] + '</td><td>' + studentSubmissionArray[2] + '</td><td>' + studentSubmissionArray[3] + '</td><td>' + studentSubmissionArray[4] + '</td><td>' + studentSubmissionArray[5] + '</td><td>' + studentSubmissionArray[6] + '</td></tr>'
}
studentSubmissionsTable = studentSubmissionsTable + '</table>'
}
return studentSubmissionsTable
}
答案 0 :(得分:3)
...因为我无法明确要求仅提供我想要的2个范围。
为此,请从您的Apps脚本编辑器导航至查看>显示项目清单-
...,然后根据需要指定身份验证范围。您可能会找到有关同一here的更多信息,并根据需要引用整个manifest structure。希望这会有所帮助。