我已经按照谷歌课堂教程在谷歌课堂中检索教师课程列表(下面的代码,相关部分来自谷歌提供的示例 Android 代码)。
现在我想检索特定班级中的学生列表,课堂网站上唯一有用的信息提供了关于 REST 调用的信息,我真的不太了解。
用于检索教师列表的 Android 代码 Google Classroom Classes
private List<String> getDataFromApi() throws IOException {
ListCoursesResponse response = mActivity.mService.courses().list()
.setPageSize(10)
.execute();
List<Course> courses = response.getCourses();
List<String> names = new ArrayList<String>();
if (courses != null) {
for (Course course : courses) {
names.add(course.getName());
}
}
return names;
}
以下是我如何修改上述代码以尝试获取班级中的学生姓名列表。然而,API 在执行此代码时会返回 NO_PERMISSION 消息,即使教师应该有权查看他们自己班级中的学生姓名。
private List<String> getDataFromApi() throws IOException {
ListCoursesResponse response = mActivity.mService.courses().list()
.setPageSize(10)
.execute();
List<Course> courses = response.getCourses();
List<String> names = new ArrayList<String>();
if (courses != null) {
names.add(courses.size()+"");
for (Course course : courses) {
names.add(course.getName());
names.add(course.getId());
ListStudentsResponse studentsResponse = mActivity.mService.courses().students().list(course.getId())
.setPageSize(40)
.execute();
List<Student> students = studentsResponse.getStudents();
names.add(students.size()+"");
for (Student student : students) {
names.add(student.toString());
}
}
}
return names;
}