Google Classroom 外掛程式現已全面開放開發人員使用!詳情請參閱
外掛程式說明文件。
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 "
開頭,向使用者顯示適當資訊。
如要瞭解 Classroom API 可能傳回的部分錯誤,請參閱「常見錯誤」頁面。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間: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."]]