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"
}
}
您可以使用响应正文来帮助调试错误原因,并向用户提供有用的信息。检查特定错误消息时,请添加尾随空格,以避免与以相同字符串开头的其他值匹配。在提供的错误示例中,您可以检查消息字段是否以 "@ClassroomApiDisabled "
开头,以向用户显示适当的信息。
如需了解 Google 课堂 API 可能会返回的一些错误,请参阅常见错误页面。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-01-30。
[null,null,["最后更新时间 (UTC):2025-01-30。"],[[["The Classroom API provides error information via HTTP error codes in the header and detailed error objects in the response body."],["Error objects in the response body contain a numerical `code`, a detailed `message` potentially including a specific error type prepended with `@`, and an HTTP request `status`."],["Developers can use the error `message` field, particularly by checking for specific prefixes like `@ClassroomApiDisabled `, to debug issues and inform users."],["The error message structure provided by the API allows for the extraction of the HTTP code, the reason behind the error and its status."],["Refer to the Common Errors page to see a detailed list of possible error messages and the actions that can be taken in response to them."]]],[]]