Google Service Client(PHP)方法文档如何工作?

问题描述 投票:1回答:1

我在使用任何未在某处明确示例的客户端服务方法时始终遇到困难。尽管遵循了文档甚至阅读了源代码,但遵循该方案我想到的类或方法的名称却永远不正确。

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的想法。问题仍然是我如何从文档中找出答案……

php google-api-php-client google-api-client
1个回答
0
投票
  • topics中没有ClassroomService成员。
  • 该成员名为courses_topics

您的代码应如下所示:

Classroom
  • $response = $this->ClassroomService->courses_topics->listCoursesTopics( $id ); 的文档没有正确给出示例代码,其中成员名为Google_Service_Classroom_CoursesTopics_Resource
  • 鉴于API文档是从源代码生成的,但是示例代码(通常)是手工编写的,因此我认为API文档是正确的,而示例代码是不正确的。我会向Google提交文档错误。

更新:

我查看了->topics,并验证了该属性被命名为the PHP source code for Google_Service_Classroom in GitHub而不是Google_Service_Classroom,因此,总而言之:示例代码错误

还有趣的是,实际源代码中的资源类型为courses_topics,但文档将其称为topics-因此文档肯定是错误的。

© www.soinside.com 2019 - 2024. All rights reserved.