Php 为什么在使用谷歌课堂API时会出现404错误?

Php 为什么在使用谷歌课堂API时会出现404错误?,php,google-api-php-client,google-classroom,Php,Google Api Php Client,Google Classroom,我正在用PHP编写一个应用程序,它将连接到我的域名的Google教室。但是,当我尝试使用Google教室API执行任何操作时,会出现以下错误: Message: Error calling GET https://www.googleapis.com/v1/courses?pageSize=100: (404) Not Found 到目前为止,我的代码是: $scopes = array( 'https://www.googleapis.com/auth/classroom.courses

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

Message: Error calling GET https://www.googleapis.com/v1/courses?pageSize=100: (404) Not Found
到目前为止,我的代码是:

$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();

我已经在Google管理控制台中为服务帐户启用了API设置中的作用域,并在开发者控制台中启用了API。我哪里出错了?

根据课堂API的定义,我认为您的端点是错误的。试着把它改成

样本请求:

GET https://classroom.googleapis.com/v1/courses?pageSize=100&key={YOUR_API_KEY}

我有一个旧版本的php客户端库。升级到最新版本解决了此问题,因为它使用了您在回答中所述的正确端点