【发布时间】:2021-10-04 14:17:44
【问题描述】:
我在使用 Google Classroom API 访问教室列表时遇到问题。我收到以下错误:
Google_Service_Exception:{ “错误”: { “代码”:403, "message": "Google Classroom API (QA) 之前未在项目 XYZ 中使用过或已禁用。通过访问 https://console.developers.google.com/apis/api/qa-classroom.sandbox.googleapis.com/overview?project=XYZ 启用它,然后重试。如果您最近启用了此 API,请等待几分钟以传播该操作到我们的系统并重试。", “错误”:[ { "message": "Google Classroom API (QA) 之前未在项目 XYZ 中使用过或已禁用。通过访问 https://console.developers.google.com/apis/api/qa-classroom.sandbox 启用它。 googleapis.com/overview?project=XYZ 然后重试。如果您最近启用了此 API,请等待几分钟让该操作传播到我们的系统并重试。", “域”:“使用限制”, "原因": "accessNotConfigured", "extendedHelp": "https://console.developers.google.com" }
问题是它没有检测到 Classroom API 被激活,因为我很确定它是激活的。如果我去开发者控制台搜索它,它会显示并被激活,并且它是在超过 24 小时前被激活的。
当我点击错误显示的链接时,它会将我带到开发者控制台,但页面是空白的,如果我打开 Firefox 控制台,我可以看到错误提示:
ERROR 错误:ga 对象:{"message":"Permission denied to get service [qa-classroom.sandbox.googleapis.com]\nHelp Token: MYTOKEN","permissionDenied":true,"errorExperience":2} `
我实际上尝试删除该项目并使用新项目再次执行此操作,但我得到了相同的结果。 我将其他 API 用作组设置、日历、联系人...并且一切正常,但 Classroom 却不行。
基本上这是我尝试使用的代码:
$connection = new Google_Client();
$connection->setClientId($clientId);
$connection->setSubject($delegatedAdmin);
$connection->useApplicationDefaultCredentials();
$connection->setIncludeGrantedScopes(true);
$connection->addScope(Google_Service_Classroom::CLASSROOM_COURSES);
$classroomService = new Google_Service_Classroom($connection);
$params = array(
'pageSize' => 10,
'pageToken' => NULL
);
$response = $classroomService->courses->listCourses($params);
在安全 > API 控制中正确配置了范围。我再说一遍,来自组设置、日历或联系人的所有其他 API 调用都可以正常工作。
有人知道我做错了什么吗?
【问题讨论】:
标签: google-classroom