【发布时间】:2021-12-18 10:16:52
【问题描述】:
我想从 Google 课堂课程列表中过滤课程对象字段。当我为课程列表调用 API 时,它会响应所有对象。但我想要特定的课程对象名称,课程列表中的部分。
$optParams = array(
'pageSize' => 100,
'courses' => 'name','section',
'fields' => 'courses(id)'
);
$results = $service->courses->listCourses($optParams);
如何使用 PHP 从课程列表中获取特定的课程对象名称和部分。
以下问题显示代码是否测试
Fatal error: Uncaught Google\Exception: (list) unknown parameter: 'courses' in C:\xampp\htdocs\classroom\vendor\google\apiclient\src\Service\Resource.php:153 Stack trace: #0 C:\xampp\htdocs\classroom\vendor\google\apiclient-services\src\Classroom\Resource\Courses.php(122): Google\Service\Resource->call('list', Array, 'Google\\Service\\...') #1 C:\xampp\htdocs\classroom\quickstart1.php(70): Google\Service\Classroom\Resource\Courses->listCourses(Array) #2 C:\xampp\htdocs\classroom\quickstart1.php(132): test('406487331584') #3 {main} thrown in C:\xampp\htdocs\classroom\vendor\google\apiclient\src\Service\Resource.php on line 153
如果代码部分如下所示,则响应中的所有对象名称都没有值,并显示我想要的字段对象名称、部分和值。
$optParams = array(
'pageSize' => 100,
'fields' => 'courses(name,section)'
);
$results = $service->courses->listCourses($optParams);
列出课程响应对象:
[courses] => Array
(
[0] => Google\Service\Classroom\Course Object
(
[collection_key:protected] => courseMaterialSets
[alternateLink] =>
[calendarId] =>
[courseGroupEmail] =>
[courseMaterialSetsType:protected] => Google\Service\Classroom\CourseMaterialSet
[courseMaterialSetsDataType:protected] => array
[courseState] =>
[creationTime] =>
[description] =>
[descriptionHeading] =>
[enrollmentCode] =>
[guardiansEnabled] =>
[id] =>
[name] => Android
[ownerId] =>
[room] =>
[section] => PC-D
[teacherFolderType:protected] => Google\Service\Classroom\DriveFolder
[teacherFolderDataType:protected] =>
[teacherGroupEmail] =>
[updateTime] =>
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
[1] => Google\Service\Classroom\Course Object
(
[collection_key:protected] => courseMaterialSets
[alternateLink] =>
[calendarId] =>
[courseGroupEmail] =>
[courseMaterialSetsType:protected] => Google\Service\Classroom\CourseMaterialSet
[courseMaterialSetsDataType:protected] => array
[courseState] =>
[creationTime] =>
[description] =>
[descriptionHeading] =>
[enrollmentCode] =>
[guardiansEnabled] =>
[id] =>
[name] => CSS
[ownerId] =>
[room] =>
[section] => PC-D
[teacherFolderType:protected] => Google\Service\Classroom\DriveFolder
[teacherFolderDataType:protected] =>
[teacherGroupEmail] =>
[updateTime] =>
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
但我需要如下所示:
[courses] => Array
(
[0] => Google\Service\Classroom\Course Object
(
[name] => Android
[section] => PC-D
)
)
【问题讨论】:
标签: php google-api google-api-php-client google-classroom