3

I have consistent difficulty using any client service method that is not explicitly exampled somewhere. Despite following the docs and even reading the sourcecode, The class or method names I come up with following the scheme are never right.

The documentation at Packagist (see 'Making Requests") says the client library classes are autogenerated from the Google endpoints, which agrees with the description in the library's docs on Github that say the pattern for accessing methods should be "$service->resource->method(args)".

So why the following?

// 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  );

According to the API Explorer all three should be fine.

What am I missing about using client service objects?

Edit Ultimately I determined the resource in my example to be 'courses_topics'; the method was correct per the docs. Thanks for the idea @ebram. The question remains how the methods are named though. courseWork is my next challenge and it does not fit the the naming pattern of topics.

Evan
  • 419
  • 4
  • 14

1 Answers1

2
  • There is no topics member of ClassroomService.
  • The member is named courses_topics.

Your code should look like this:

$response = $this->ClassroomService->courses_topics->listCoursesTopics( $id  );
  • The documentation for Google_Service_Classroom_CoursesTopics_Resource does incorrectly give sample code where the member is named ->topics.
  • Given that API documentation is generated from source, but sample code is (generally) written by hand, I'll assume the API documentation is correct and the sample code is incorrect. I'd file a documentation-bug with Google.

Update:

I looked at the PHP source code for Google_Service_Classroom in GitHub and verified that the property is named courses_topics instead of topics, so in conclusion: the sample code is wrong.

What's also interesting is the resource-type in the actual source-code is Google_Service_Classroom_Resource_CoursesTopics but the documentation refers to it as Google_Service_Classroom_CoursesTopics_Resource - so that documentation is definitely wrong.

Dai
  • 141,631
  • 28
  • 261
  • 374
  • Thanks for the help, although my question edit indicated that I also discovered this. The question is actually directed at where the methods are documented. I'm having the exact same difficulty now trying to run listCourseWork(). The docs make it look like `service->courseWork->listCoursesCourseWork()` is a thing, meanwhile the topics example had me try `service->course_work->listCoursesCourseWork()` ... both produce undefined property error. Is there just no CANNONICAL naming to these!? – Evan Feb 29 '20 at 17:44