为什么我在使用 Google Classroom API 时会收到 404 错误?

amb*_*ide 2 php google-api-php-client google-classroom

我正在用 PHP 编写一个应用程序,它将连接到我域的 Google Classroom。但是,当我尝试使用 Google Classroom API 执行任何操作时出现以下错误:

Message: Error calling GET https://www.googleapis.com/v1/courses?pageSize=100: (404) Not Found
Run Code Online (Sandbox Code Playgroud)

到目前为止我的代码:

$scopes = 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'
);

$gServiceEmail = "random@developer.gserviceaccount.com";
$gServiceKey = file_get_contents("../path/to/cert.p12");

$client = new Google_Client();
$gAuth = new Google_Auth_AssertionCredentials(
  $gServiceEmail,
  $scopes,
  $gServiceKey
);

$gAuth->sub = "user@mydomain.com";
$client->setAssertionCredentials($gAuth);

$service = new Google_Service_Classroom($client);
$results = $service->courses->listCourses();
Run Code Online (Sandbox Code Playgroud)

我已在 Google 管理控制台的 API 设置中为服务帐户启用了范围,并在开发人员控制台中启用了 api。我哪里错了?

gob*_*lin 5

根据Classroom API的文档,我认为您的端点是错误的。尝试将其更改为 https://classroom.googleapis.com

样品要求:

GET https://classroom.googleapis.com/v1/courses?pageSize=100&key={YOUR_API_KEY}
Run Code Online (Sandbox Code Playgroud)