1

我正在使用 Google Apps Script 开发一个网络应用程序,但在理解如何处理授权时遇到了一些麻烦。以使用该应用程序的用户身份访问该网络应用程序时,它会提示授权,并且一切正常。但是,我调用 userProfiles.get 并查找学生电子邮件地址,它会返回没有电子邮件的个人资料。

function classRosters() {
  var teacher = Classroom.UserProfiles.get(Session.getActiveUser().getEmail());
  var classList = Classroom.Courses.list({teacherId: teacher.id}).courses;
  var classes = [];

  for (i in classList) {
    if (classList[i].courseState != 'ACTIVE') {
      continue;
    }
    var class = classList[i];
    var classId = classList[i].id;
    var className = classList[i].name;
    classes.push([className]);
    var teacherId = Classroom.Courses.Teachers.get(classId, classList[i].ownerId).userId;
    var teacherEmail = Classroom.UserProfiles.get(teacherId);


      var title = Classroom.Courses.get(classId).name;
      var students = Classroom.Courses.Students.list(classId).students;
      var studentArray = [];
      if (students) {
        for (j in students) {
          var currStudent = students[j];
          var email = Classroom.UserProfiles.get(currStudent.userId).emailAddress;
          var email = Classroom.Courses.Students.get(classId, currStudent.userId).profile.emailAddress;
          studentArray.push(email);
          Logger.log(email);
        }
      }
      for (j in classes) {
        if (className.indexOf(classes[j]) > -1) {
          var classIndex = +j;
          classes[classIndex].push(studentArray);
        } 
      }

  }
  return classes;
}

我玩过 API 资源管理器,它显示教室.profile.email 是必需的,但这不包括在范围内。当我使用 API 资源管理器时,我可以授权,并且它可以工作,并且我的 Web 应用程序也可以正常工作,直到资源管理器的授权到期。

课堂高级服务有什么方法可以在GAS库中提示授权吗?我找不到任何特定于 GAS 的东西,而不是整个 API 的一部分。

谢谢,詹姆斯

4

1 回答 1

3

Unfortunately Apps Script doesn't allow you to request additional scopes for your advanced services. The email and photos scopes aren't required to execute the method, but are required to return email and photo data in the response. You can follow issue 3070 for progress on this problem.

Update 2015-08-17:

We just implemented a workaround, which is that the Classroom advanced service now always prompts for the following fixed set of scopes:

https://www.googleapis.com/auth/classroom.courses https://www.googleapis.com/auth/classroom.rosters https://www.googleapis.com/auth/classroom.profile.emails https://www.googleapis.com/auth/classroom.profile.photos

This provides access to emails, but does mean that the scopes requested for a given script may be more than it actually needs. We hope this unblocks admins that are trying to use Apps Script to manage their Classroom data, while we work on a longer-term solution for dealing with optional scopes in Apps Script.

于 2015-08-06T13:53:32.630 回答