I'm trying to create a course using the Google_Service_Classroom API, using PHP, but I get an error in the call.
<?php
require_once __DIR__.'/vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=C:\laragon\www\classroom.json');
$user_admin= 'test00001@gmail.com';
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setSubject($user_admin);
$client->setScopes(array(
'https://www.googleapis.com/auth/classroom.courses',
'https://www.googleapis.com/auth/classroom.courses.readonly',
'https://www.googleapis.com/auth/classroom.rosters',
'https://www.googleapis.com/auth/classroom.rosters.readonly',
'https://www.googleapis.com/auth/classroom.profile.emails',
'https://www.googleapis.com/auth/classroom.profile.photos'
));
$service = new Google_Service_Classroom($client);
$postBody = array(
"id" => "1",
"name" => "Course 01",
"section" => "15/19",
"descriptionHeading" => "Course 01 test 001",
"description" => "Course 01 test",
"room" => "03/12",
"creationTime" => "2020-12-12T11:48:50.951Z",
"enrollmentCode" => "yzdeeee",
"courseState" => "ACTIVE",
"alternateLink" => "https://classroom.google.com/c/coursetest01"
);
$optParams = array();
$results = $service->courses->create($postBody, $optParams);
echo '<pre>', print_r($results, true);
exit;
My return:
Fatal error: Uncaught TypeError: Argument 1 passed to Google_Service_Classroom_Resource_Courses::create() must be an instance of Google_Service_Classroom_Course, array given, called in C:\laragon\www\teste-03.php on line 41 and defined in C:\laragon\www\vendor\google\apiclient-services\src\Google\Service\Classroom\Resource\Courses.php:47 Stack trace: #0 C:\laragon\www\teste-03.php(41): Google_Service_Classroom_Resource_Courses->create(Array, Array) #1 {main} thrown in C:\laragon\www\vendor\google\apiclient-services\src\Google\Service\Classroom\Resource\Courses.php on line 47
I'm seeing the documents, but I don't see where to fix this problem.