classroom.profile.emails需要授权

时间:2015-08-06 02:01:59

标签: google-classroom

我正在使用Google Apps脚本中的网络应用,我在理解如何处理授权方面遇到了一些麻烦。当用户使用应用程序访问Web应用程序时,它会提示授权,一切正常。但是,我打电话给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资源管理器,它显示了classroom.profile.email是必需的,但这不包含在范围内。当我使用API​​资源管理器时,我可以授权,并且它可以工作,我的网络应用程序也可以正常工作,直到资源管理器的授权到期为止。

是否有任何方法可以在GAS库中提示对Classroom高级服务进行授权?我找不到任何特定于GAS的内容,也不是整个API的一部分。

谢谢, 詹姆斯

1 个答案:

答案 0 :(得分:0)

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.