0

使用 HTTP GET 请求,您将如何仅获取活动的类。您能否将参数添加到仅返回活动类列表的 Google API URL?或者您是否必须搜索返回的数组并删除使用 for 循环归档的任何类?

    var classroom = new XMLHttpRequest();
    var accessToken = localStorage.getItem('accessToken');
    classroom.open('GET',
      'https://classroom.googleapis.com/v1/courses');
    classroom.setRequestHeader('Authorization',
      'Bearer ' + accessToken);
    classroom.send();

    classroom.onload = function () {
        if (classroom.readyState === classroom.DONE) {
            if (classroom.status === 200) {
              var response = JSON.parse(classroom.response);
              vm.classes = response.courses;
              console.log(response);
              for (var i = 0; i < response.courses.length; i++){
                var courses = response.courses[i];
                console.log(courses.name);

              }
            } else {
              console.log("Error Unknown");
            }
        }
    };

任何帮助将非常感激。谢谢!

4

3 回答 3

1

还没有像用户对象那样的过滤选项。(至少据我所知,这已记录在案)。所以是的,您必须提取所有课程,然后过滤掉存档的课程。https://developers.google.com/classroom/reference/rest/v1/courses有一个 CourseState 部分列出了课程可能处于的 5 种状态。 [COURSE_STATE_UNSPECIFIED, ACTIVE, ARCHIVED, PROVISIONED, DECLINED]

于 2016-08-09T20:45:09.750 回答
0

通读文档,courses.list返回请求用户被允许查看的课程列表。它没有说明仅检索活动类的直接方法。您可能不得不求助于您所说的实施。

于 2016-08-10T07:30:19.693 回答
0

尝试这个:

function get_courses(student) {
  var optionalArgs = {
    studentId: student
  };
  var response = Classroom.Courses.list(optionalArgs);
  var courses = response.courses;
  var active_courses = [];
  if (courses && courses.length > 0) {
    for (i = 0; i < courses.length; i++) {
      var course = courses[i];
      if(course.courseState == "ACTIVE"){

        active_courses.push(course);

        Logger.log('%s (%s)', course.name, course.id);
      }
    }
  } else {
    Logger.log('No courses found.');
  }

  return active_courses;
}
于 2016-09-16T06:50:07.557 回答