【问题标题】:Google Classroom API returns student profile JSON having no email addressGoogle Classroom API 返回没有电子邮件地址的学生资料 JSON
【发布时间】:2016-04-05 06:58:32
【问题描述】:

从 Google 获取不包含任何电子邮件地址且用户名包含值“未知用户”的学生 JSON。

 {
     "courseId":"1234",
     "profile":{//No email address
             "id":"openId",
             "name":{"fullName":"Unknown user"},//Why "Unknown user"
             "photoUrl":"correct_url"
     },
     "userId":"openId"
}

我们无法访问教师的 Google 课堂帐户,因此我们正在尝试使用测试帐户重现该问题。只有少数用户会发生这种情况,其他所有用户都可以正常工作。

我们正在使用 Google Classroom 的 Java API。

我们正在使用的示例代码:

Classroom service = getGoogleClassRoomService(accessToken);
if(service != null) {
    ListStudentsResponse studentsResponse = service.courses().students().list(courseId).execute();
    List<Student> students = studentsResponse.getStudents();
    if(students != null) {
        for (Student student : students) {
            if (student.getProfile().getEmailAddress() != null) {
                //Processing student data
            }
        }
    }
}

需要知道学生的电子邮件地址可以为空的情况,技术上它不应该为空。

示例学生资料 JSON 参考:https://developers.google.com/classroom/reference/rest/v1/userProfiles#resource-userprofile

验证用户时请求的范围:

https://www.googleapis.com/auth/classroom.courses.readonlyhttps://www.googleapis.com/auth/classroom.profile.emailshttps://www.googleapis.com/auth/classroom.profile.photoshttps://www.googleapis.com/auth/classroom.rosters.readonly

【问题讨论】:

  • 我知道这是一个很老的问题,但你找到任何解决方案了吗?
  • 无解,只是忽略了这些数据。

标签: google-classroom


【解决方案1】:

要返回电子邮件地址,您需要申请特殊的 https://www.googleapis.com/auth/classroom.profile.emails OAuth 范围。

【讨论】:

  • 已经这样做了,更新了问题。正如我已经提到的,代码对所有其他用户都可以正常工作,所以它不应该是范围问题。
【解决方案2】:

用户是否已被删除?在某些情况下,如果用户已被删除,API 将返回一个名称为“未知用户”的“用户”(并且没有电子邮件地址)。

【讨论】:

  • 我看到 OP 已经接受了这一点,但我遇到了同样的问题,而且这些不是已删除的用户。如果我找到解决方案,我会在这里参考。
【解决方案3】:

需要知道学生的电子邮件地址可以为空的情况,从技术上讲它不应该为空。

当 G-Suite 管理员删除学生帐户时会发生这种情况。这只会删除用户帐户,不会将用户从 Google 课堂中删除。这将在该用户所在的教室中留下一个幽灵用户。

幸运的是,G-Suite 允许在 20 天内恢复已删除的用户。如果管理员恢复了此类用户,您将能够看到他们各自教室中的学生,并可以从每个教室优雅地删除他们。

如果用户删除后 20 天过去了,我不确定如何解决此问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    • 2018-12-11
    • 1970-01-01
    • 1970-01-01
    • 2020-05-10
    • 1970-01-01
    相关资源
    最近更新 更多