【发布时间】:2019-09-24 19:12:32
【问题描述】:
我是使用 Google Classroom API 的新手,我正在尝试获取此类课程及其学生的列表:
课程 1:
学生: 学生 1.1 学生 1.2 学生 1.3
课程 2:
学生: 学生 2.1 学生 2.2 学生 2.3 学生 2.4
...
但是我的代码得到了:
课程 1: 课程2:
学生: 学生 1.1 学生 1.2 学生 1.3
学生: 学生 2.1 学生 2.2 学生 2.3 学生 2.4
你知道为什么吗?
function listCourses() {
gapi.client.classroom.courses.list({
pageSize: 10,
}).then(function(response) {
var courses = response.result.courses;
appendPre('Courses:');
if (courses.length > 0) {
for (i = 0; i < courses.length; i++) {
var course = courses[i];
appendPre(course.name+":"+course.id)
listStudents(course.id);
}
} else {
appendPre('No courses found.');
}
});
}
function listStudents(c) {
gapi.client.classroom.courses.students.list({
courseId: c
}).then(function(response) {
console.log(response.result);
var students = response.result.students;
appendPre('students:');
if (students.length > 0) {
for (i = 0; i < students.length; i++) {
var student = students[i];
appendPre(c+":"+student.userId+":"+student.profile.name.fullName)
}
} else {
appendPre('No students found.');
}
});
}
【问题讨论】:
标签: javascript google-api google-classroom