Authorization needed for classroom.profile.emails

喜你入骨 提交于 2019-12-25 04:36:07

问题


I'm working on a web app in Google Apps Script, and I'm having some trouble understanding how the authorization is handled. When accessing the web app as the user using the app, it prompts for authorization, and everything appears okay. However, I'm call userProfiles.get and looking for student email addresses, and it returns the profile without the email.

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;
}

I've played with the API explorer, and it shows that classroom.profile.email is required, but that's not included in the scopes. When I use the API explorer, I can authorize, and it works, and my web app will work as well until the authorization from the explorer expires.

Is there any method to prompt for authorization in the GAS library for the Classroom advanced service? I can't find anything much that's specific to GAS and not part of the overall API.

Thanks, James


回答1:


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.



来源:https://stackoverflow.com/questions/31845646/authorization-needed-for-classroom-profile-emails

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