简体   繁体   English

如何编辑范围? // 谷歌课堂控制谷歌应用脚​​本中学生访问权限范围

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

I am a high school teacher writing a Google Apps Script against Google Classroom.我是一名高中老师,正在针对 Google Classroom 编写 Google Apps 脚本。 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.我已经成功地编写了代码,这样我就可以通过在代码中显式地放置学生的 Id 以我的权限运行它。 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.此外,我已经成功地用Python编写了代码,我可以其中明确设置学生访问此(且仅此)信息所需的两个范围。 However, Google Apps Scripts automatic scope generation has me stymied because I can't explicitly ask for only the 2 scopes I want.但是,Google Apps Scripts 自动范围生成让我受阻,因为我不能明确要求仅我想要的 2 个范围。

Here are the two scopes that worked when I wrote it in python:以下是我用 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.以下是 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

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
}

...because I can't explicitly ask for only the 2 scopes I want. ...因为我不能明确要求仅我想要的 2 个范围。

For this, please navigate to View > Show project manifest from your Apps Script editor -为此,请从您的 Apps 脚本编辑器导航到查看 > 显示项目清单-

舱单

...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.希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Google Apps Script 和 Google Classroom 创建学生 - Creating a student with Google Apps Script & Google Classroom Google课堂API返回“请求的身份验证范围不足” - Google classroom API returned “Request had insufficient authentication scopes” Google API多个范围 - Google API multiple scopes 如何使用 Google Apps 脚本中的按钮打开另一个页面? - How do I open another page with a button in Google Apps Scripts? 在greasemonkey中谷歌地图和范围 - google maps and scopes within greasemonkey 如何在Chrome扩展程序中使用Google Classroom API? - How do I use the Google Classroom API in chrome extension? 我是否需要提交以下Google驱动器范围的验证请求,才能从选择器中下载文件? - Do i require to Submit a verfication request for the following google drive scopes in order to download a file from picker? 如何在我的Google Apps脚本/ Google表格HTML中包含脚本? - How do I include scripts in my Google Apps Script/Google Sheets HTML? 通过脚本授予编辑权限(谷歌应用脚本) - give edit permission by script (google apps script) 块范围如何访问封闭的 scope - How do block scopes have access to enclosing scope
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM