我正在尝试借助我的 android 项目中的 Classroom API(Java 语言)检索给定教室的所有学生。我能够成功检索课程的课程和提交的课程,但它在异常消息中引发了一些权限错误。
我参考了官方文档来选择范围:
https://developers.google.com/classroom/guides/auth
抛出异常的代码:
ListStudentsResponse studentsResponse = mClassroomService.courses().students().list(courseId).execute();
我包含的范围:
new Scope(ClassroomScopes.CLASSROOM_COURSES_READONLY),
new Scope(ClassroomScopes.CLASSROOM_GUARDIANLINKS_STUDENTS),
new Scope(ClassroomScopes.CLASSROOM_PROFILE_EMAILS),
new Scope(ClassroomScopes.CLASSROOM_COURSEWORK_STUDENTS_READONLY),
new Scope(ClassroomScopes.CLASSROOM_PROFILE_PHOTOS)
我从异常中得到的错误信息
403 Forbidden
{
"code": 403,
"errors": [
{
"domain": "global",
"message": "The caller does not have permission",
"reason": "forbidden"
}
],
"message": "The caller does not have permission",
"status": "PERMISSION_DENIED"
}
定义的常量..
public static final String CLASSROOM_COURSES_READONLY = "https://www.googleapis.com/auth/classroom.courses.readonly";
public static final String CLASSROOM_GUARDIANLINKS_STUDENTS = "https://www.googleapis.com/auth/classroom.guardianlinks.students";
public static final String CLASSROOM_PROFILE_EMAILS = "https://www.googleapis.com/auth/classroom.profile.emails";
public static final String CLASSROOM_PROFILE_PHOTOS = "https://www.googleapis.com/auth/classroom.profile.photos";
public static final String CLASSROOM_COURSEWORK_STUDENTS_READONLY = "https://www.googleapis.com/auth/classroom.coursework.students.readonly";