3

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 Answers1

0

...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 -

Manifest

...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.

Sourabh Choraria
  • 2,255
  • 25
  • 64