How do I edit scopes? // Google Classroom control permission scopes in google apps scripts for student access

时光总嘲笑我的痴心妄想 提交于 2021-02-07 04:01:52

问题


I am a high school teacher writing a Google Apps Script against Google Classroom. I want to create a spreadsheet like view of my students grades that my students can access with their credentials.

I have successfully written the code so that I can run it with my privileges by explicitly placing the student's Id in the code. Additionally, I have successfully written the code in Python where I can explicitly set just the two scopes a student needs to access this (and only this) information. However, Google Apps Scripts automatic scope generation has me stymied because I can't explicitly ask for only the 2 scopes I want.

Here are the two scopes that worked when I wrote it in python:

SCOPES = ['https://www.googleapis.com/auth/classroom.coursework.me.readonly https://www.googleapis.com/auth/classroom.student-submissions.me.readonly']

And here are the scopes that are automatically generated by Google Apps Scripts.

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

Here is my code:

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
}

回答1:


...because I can't explicitly ask for only the 2 scopes I want.

For this, please navigate to View > Show project manifest from your Apps Script editor -

...and then specify the auth scopes as required. You may find more information about the same here and refer to the entire manifest structure as needed. Hope this helps.



来源:https://stackoverflow.com/questions/46142164/how-do-i-edit-scopes-google-classroom-control-permission-scopes-in-google-ap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!