我正在用PHP编写一个应用程序,它将连接到我的域名的Google课堂。但是,当我尝试使用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。我哪里错了?
答案 0 :(得分:4)
根据Classroom API的documentation,我认为您的端点是错误的。尝试将其更改为https://classroom.googleapis.com
样品申请:
GET https://classroom.googleapis.com/v1/courses?pageSize=100&key={YOUR_API_KEY}