gpt4 book ai didi

php - 为什么使用 Google Classroom API 时会出现 404 错误?

转载 作者:行者123 更新时间:2023-12-02 21:09:17 24 4
gpt4 key购买 nike

我正在用 PHP 编写一个应用程序,它将连接到我域的 Google Classroom。但是,当我尝试使用 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 = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d5f4c434942406d49485b4841425d485f034a5e485f5b444e484c4e4e42584359034e4240" rel="noreferrer noopener nofollow">[email protected]</a>";
$gServiceKey = file_get_contents("../path/to/cert.p12");

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

$gAuth->sub = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7a0f091f083a17031e15171b131454191517" rel="noreferrer noopener nofollow">[email protected]</a>";
$client->setAssertionCredentials($gAuth);

$service = new Google_Service_Classroom($client);
$results = $service->courses->listCourses();

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

最佳答案

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

示例请求:

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

关于php - 为什么使用 Google Classroom API 时会出现 404 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34416792/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com