Google 课堂插件现已面向开发者正式推出!如需了解详情,请参阅
插件文档。
Google Classroom API 错误结构
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Classroom API 会返回错误信息,帮助开发者调试问题,并向最终用户提供实用可行的信息。本指南介绍了如何解析 API 返回的错误信息。
Classroom API 会返回两个级别的错误信息:
- 标头中的 HTTP 错误代码。
- 响应正文中的对象,包含其他详细信息。
错误消息结构
响应正文中返回的错误包括以下字段:
code
:数字 HTTP 错误代码。例如 403
。
message
:有关错误的更多详细信息。如果错误消息可用,系统会在其前面添加 @
和特定错误类型。例如 @ClassroomApiDisabled
。
status
:HTTP 请求状态。例如 PERMISSION_DENIED
或 NOT_FOUND
。
如果请求失败并显示 ClassroomApiDisabled
错误,则响应将如下所示:
{
"error": {
"code": 403,
"message": "@ClassroomApiDisabled The user is not permitted to access the Classroom API.",
"status": "PERMISSION_DENIED"
}
}
您可以使用响应正文来帮助您调试错误原因,并向用户提供有用的信息。检查特定错误消息时,请添加尾随空格,以避免匹配以相同字符串开头的其他值。在提供的错误示例中,您可以检查 message 字段是否以 "@ClassroomApiDisabled "
开头,以便向用户显示相应的信息。
如需了解 Classroom API 可能会返回的一些错误,请参阅常见错误页面。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[],[],null,["# Google Classroom API error structure\n\nThe Classroom API returns error information that can help developers\ndebug issues and provide helpful, actionable information to end users. This\nguide explains how to parse error information returned from the API.\n\nThe Classroom API returns two levels of error information:\n\n- HTTP error code in the header.\n- An object in the response body with additional details.\n\nError message structure\n-----------------------\n\nErrors returned in the response body include the following fields:\n\n- `code`: The numerical HTTP error code. For example, `403`.\n- `message`: Additional details about the error. When available, the error message is prepended with `@` and a specific error type. For example, `@ClassroomApiDisabled`.\n- `status`: The HTTP request status. For example, `PERMISSION_DENIED` or `NOT_FOUND`.\n\nIf a request failed with a [`ClassroomApiDisabled`](/workspace/classroom/troubleshooting/common-errors#classroom-api-disabled) error, the response would\nbe: \n\n {\n \"error\": {\n \"code\": 403,\n \"message\": \"@ClassroomApiDisabled The user is not permitted to access the Classroom API.\",\n \"status\": \"PERMISSION_DENIED\"\n }\n }\n\nYou can use the response body to help you debug the cause of the error and\nprovide helpful information to users. Include a trailing space when checking\nfor a specific error message to avoid matching other values that start with\nthe same string. In the provided error example, you can check if the message\nfield begins with `\"@ClassroomApiDisabled \"` to present appropriate information\nto users.\n\nReference the [Common errors](/workspace/classroom/troubleshooting/common-errors) page for information on some errors that\ncan be returned by the Classroom API."]]