I have followed the Google Classroom tutorial on retrieving a list of a teacher's classes in Google Classroom (code below, relevant part from example Android code provided by Google).
Now I would like to retrieve a list of students within a specific class, and the only helpful information on the Classroom site give info on REST calls which I really don't know much about yet.
Android code to Retrieve a list of a teachers 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;
}
Here's how I modified the above code to try and get the list of student names in the classes as well. However the API returns a message of NO_PERMISSION when executing this code, even though a teacher should have permission to view the student names in their own 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) {
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;
}