PHP Google Classroom API list_classes

我在使用 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


哈士奇WWW
浏览 136回答 3
3回答

扬帆大鱼

&nbsp; $results = $service->courses->listCourses($optParams);if (count($results->getCourses()) == 0) {&nbsp; &nbsp; // print "No courses found.\n";} else {&nbsp; &nbsp; // print "Courses:\n";&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; $insert_array_fill = '';&nbsp; &nbsp; $select_array_fill = '';&nbsp; &nbsp; foreach ($results->getCourses() as $course) {&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; //echo "<hr>";&nbsp; &nbsp; &nbsp; &nbsp; if(strcmp($course->getCourseState(), 'ACTIVE') == 0){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $courses .= $course->getName()." - ".$course->getId()." - ".$course->getAlternateLink()." - ".$course->getOwnerId()."<br />";//." ". $course->getId();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}

皈依舞

所选解决方案不正确。问题是您拼错了键(courseState而不是courseState&nbsp;s,缺少s)。应该 -'courseStates'&nbsp;&nbsp;=>&nbsp;'ACTIVE'此答案与 Google API v2.4.0 版本相关。

RISEBY

解决方案变量CourseState的类型为Enum和 not String,因此,它必须作为 an 访问enum,而不是作为string。将以下内容添加到optParams:'courseState' => 'courseState::ACTIVE',我希望这对你有帮助。如果您需要其他任何信息或者您不明白某些内容,请告诉我。:)
打开App,查看更多内容
随时随地看视频慕课网APP