PHP Google Classroom API list_classes

问题描述 投票:0回答:3

我在使用 PHP 进行 Google API 集成时遇到问题。

下面的代码将拉出类,但它会拉出所有类(ACTIVE、ARCHIVED等...)。我只想要活跃课程。

问题是当我添加 courseStates 参数时它说它不存在

$service = new Google_Service_Classroom($client);
            $courses = '';

            $optParams = array(
//none of these seem to work
              //'courseStates' => 'ACTIVE',
              //'courseState' => 'ACTIVE',
              //'CourseStates' => 'ACTIVE',
              'pageSize' => 50,
              'studentId' => $user_email
            );
            $results = $service->courses->listCourses($optParams);

            if (count($results->getCourses()) == 0) {
             // print "No courses found.\n";
            } else {
             // print "Courses:\n";
              foreach ($results->getCourses() as $course) {
                                $courses .= $course->getName()."<br />";//." ". $course->getId();

                //printf("%s (%s)\n", $course->getName(), $course->getId());
              }
            }

方法在这里,但是显示的选项都不起作用 https://developers.google.com/classroom/reference/rest/v1/courses/list

php api google-classroom
3个回答
1
投票
  $results = $service->courses->listCourses($optParams);
if (count($results->getCourses()) == 0) {
    // print "No courses found.\n";
} else {
    // print "Courses:\n"; 
    
    $insert_array_fill = '';
    $select_array_fill = '';
    foreach ($results->getCourses() as $course) {
        // 
        //echo "<hr>";
        if(strcmp($course->getCourseState(), 'ACTIVE') == 0){
            
            $courses .= $course->getName()." - ".$course->getId()." - ".$course->getAlternateLink()." - ".$course->getOwnerId()."<br />";//." ". $course->getId();
        }
    }
}

0
投票

选择的解决方案不正确。 问题是您拼错了键(courseState而不是courseStates,缺少s)。

应该是-

'courseStates'  => 'ACTIVE'

此答案与 Google API v2.4.0 版本相关。


-1
投票

变量 CourseState 的类型为

Enum
而不是
String
,因此,它必须作为
enum
而不是
string
进行访问。将以下内容添加到
optParams

'courseState' => 'courseState::ACTIVE',
© www.soinside.com 2019 - 2024. All rights reserved.