【发布时间】:2015-07-29 01:15:08
【问题描述】:
我已按照 Google 课堂教程在 Google 课堂中检索教师的课程列表(代码如下,相关部分来自 Google 提供的示例 Android 代码)。
现在我想检索特定班级中的学生列表,而 Classroom 网站上唯一有用的信息是关于 REST 调用的信息,我真的不太了解。
用于检索教师 Google Classroom Classes 列表的 Android 代码
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;
}
【问题讨论】:
-
您的问题不清楚,您想在您的应用程序中使用 Google Class room API 还是您正在开发一个示例应用程序,您正在创建师生管理系统?
-
我已经有一个供教师使用的 Android 应用程序,我想使用 Classroom API 来获取课程列表以及每门课程中的学生姓名。 Classroom 团队发布了一些示例代码,展示了如何验证用户身份并获取用户 ID 下的课程列表。它工作得很好。现在我想知道如何获取特定 classid 下的学生姓名列表 - 这一切都适用于 Android 应用程序。
-
如果有任何可用的 API,那么它应该可以工作,您使用的是哪个 API?在这里发帖。
-
我让它的工作方式与您的代码类似。通过 OAuth2 授权时,我确实必须将 ClassroomScopes.CLASSROOM_ROSTERS_READONLY 添加到范围。如果您从快速入门开始工作,请使用 MainActivity - private static final String[] SCOPES = { ClassroomScopes.CLASSROOM_ROSTERS_READONLY, ClassroomScopes.CLASSROOM_PROFILE_EMAILS };
标签: android google-api google-classroom