我在使用任何未在某处明确示例的客户端服务方法时始终遇到困难。尽管遵循了文档甚至阅读了源代码,但遵循该方案我想到的类或方法的名称却永远不正确。
Packagist处的文档(请参见“发出请求”)说,客户端库类是从Google端点自动生成的,这与library's docs on Github中的描述一致,即访问方法的模式应为“$service->resource->method(args)
“。
那么为什么要以下?
// works:
// I get a countable object of active classrooms owner by the specified id
$response = $this->ClassroomService->courses->listCourses([
'courseStates' => 'ACTIVE',
'teacherId' => 'me']);
// works:
// I get an instance of the single classroom's object containing lots of meta data
$response = $this->ClassroomService->courses->get( $id );
// does not work:
// 500 error, obj has no such method
$response = $this->ClassroomService->topics->listCoursesTopics( $id );
根据API Explorer,这三个都应该没问题。
关于使用客户端服务对象我缺少什么?
编辑最终,我将示例中的资源确定为“ courses_topics”。该方法是正确的,根据文档。谢谢@ebram的想法。问题仍然是我如何从文档中找出答案……
topics
中没有ClassroomService
成员。courses_topics
。Classroom
documentation底部的“属性摘要”中。您的代码应如下所示:
Classroom
$response = $this->ClassroomService->courses_topics->listCoursesTopics( $id );
的文档没有正确给出示例代码,其中成员名为Google_Service_Classroom_CoursesTopics_Resource
。我查看了->topics
,并验证了该属性被命名为the PHP source code for Google_Service_Classroom
in GitHub而不是Google_Service_Classroom
,因此,总而言之:示例代码错误。
还有趣的是,实际源代码中的资源类型为courses_topics
,但文档将其称为topics
-因此文档肯定是错误的。