2

ドメインの Google Classroom に接続する PHP でアプリを作成しています。ただし、Google Classroom 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 を有効にしました。どこが間違っていますか?

4

2 に答える 2

5

Classroom APIのドキュメントによると、エンドポイントが間違っていると思います。https://classroom.googleapis.comに変更してみて ください

サンプルリクエスト:

GET https://classroom.googleapis.com/v1/courses?pageSize=100&key={YOUR_API_KEY}
于 2015-12-23T16:07:14.933 に答える