首页 > 解决方案 > 如何修复从谷歌课堂更新草稿成绩和学生提交的指定成绩的项目权限被拒绝问题

问题描述

我想使用 API 从 Google Classroom 更新草稿成绩和指定成绩。当我使用Try this API测试更新草稿成绩和分配的成绩时,会出现以下问题。

问题:1

{
  "error": {
    "code": 403,
    "message": "@ProjectPermissionDenied The Developer Console project is not permitted to make this request.",
    "status": "PERMISSION_DENIED"
  }
}

显示弹出错误消息:

此错误可能是由于使用的凭据类型不足。尝试使用 OAuth 2.0。

本地主机代码:

$client = getClient();
        $service = new Google_Service_Classroom($client);
        $courseId = '393351980716';
        $courseWorkId = '393445838699';
        $id = 'Cg0Iu5q5vHkQ657M2bkL';
        $post_body = new Google_Service_Classroom_StudentSubmission(array(
            'assignedGrade' => 10,
            'draftGrade' => 90
        ));
        $params = array(
            'updateMask' => 'assignedGrade,draftGrade'
          );

        $list = $service->courses_courseWork_studentSubmissions->patch($courseId, $courseWorkId, $id, $post_body,$params);

然后,当我在 localhost 上运行上述代码时,我看到了问题 2:

问题2

Fatal error: Uncaught Google\Service\Exception: {
  "error": {
    "code": 403,
    "message": "@ProjectPermissionDenied The Developer Console project is not pe
rmitted to make this request.",
    "errors": [
      {
        "message": "@ProjectPermissionDenied The Developer Console project is no
t permitted to make this request.",
        "domain": "global",
        "reason": "forbidden"
      }
    ],
    "status": "PERMISSION_DENIED"
  }
}

如何解决这个问题呢?

标签: phpgoogle-oauthgoogle-api-php-clientgoogle-api-clientgoogle-classroom

解决方案


对于该 API 请求,您的 API 密钥需要以下授权范围之一

授权范围需要以下 OAuth 范围之一:

https://www.googleapis.com/auth/classroom.coursework.students https://www.googleapis.com/auth/classroom.coursework.me


推荐阅读