Google Drive API 會傳回兩種層級的錯誤資訊:
- HTTP 錯誤代碼和標頭訊息。
- 回應主體中的 JSON 物件,其中包含可協助您決定處理錯誤的其他詳細資料。
Google 雲端硬碟應用程式應找出並處理使用 REST API 時可能發生的所有錯誤。本指南說明如何解決特定 Drive API 錯誤。
HTTP 狀態碼摘要
錯誤代碼 | 說明 |
---|---|
200 - OK |
要求成功 (這是成功 HTTP 要求的標準回應)。 |
400 - Bad Request |
要求發生用戶端錯誤,因此無法執行要求。 |
401 - Unauthorized |
要求含有無效憑證, |
403 - Forbidden |
已收到並理解要求,但使用者沒有執行該要求的權限。 |
404 - Not Found |
找不到要求的網頁。 |
429 - Too Many Requests |
對 API 提出的要求過多。 |
500, 502, 503, 504 - Server Errors |
處理要求時發生未預期的錯誤。 |
400 錯誤
這些錯誤表示要求無法接受,通常是缺少必要參數所致。
badRequest
程式碼的下列任一問題都可能發生這項錯誤:
- 尚未提供必填欄位或參數。
- 提供的值或提供的欄位組合無效。
- 您嘗試為雲端硬碟檔案新增重複的上層項目。
- 您嘗試新增的父項會在目錄圖中建立循環。
以下 JSON 範例代表這個錯誤:
{
"error": {
"code": 400,
"errors": [
{
"domain": "global",
"location": "orderBy",
"locationType": "parameter",
"message": "Sorting is not supported for queries with fullText terms. Results are always in descending relevance order.",
"reason": "badRequest"
}
],
"message": "Sorting is not supported for queries with fullText terms. Results are always in descending relevance order."
}
}
如要修正這個問題,請檢查 message
欄位並做出相應調整。
invalidSharingRequest
有幾個原因會造成這個錯誤。如要判斷原因,請評估傳回的 JSON 的 reason
欄位。這類錯誤的常見原因如下:
- 成功共用,但通知電子郵件未正確傳送。
- 不允許這位使用者變更存取控制清單 (ACL)。
message
欄位代表實際的錯誤。
分享成功,但通知電子郵件未正確傳送
以下 JSON 範例代表這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidSharingRequest",
"message": "Bad Request. User message: \"Sorry, the items were successfully shared but emails could not be sent to email@domain.com.\""
}
],
"code": 400,
"message": "Bad Request"
}
}
如要修正這個錯誤,請通知使用者 (分享者) 無法分享,因為通知電子郵件無法傳送至目的地電子郵件地址。使用者應確保他們擁有正確的電子郵件地址,並且可以接收電子郵件。
這位使用者不允許變更 ACL 權限
以下 JSON 範例代表這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidSharingRequest",
"message": "Bad Request. User message: \"ACL change not allowed.\""
}
],
"code": 400,
"message": "Bad Request"
}
}
如要修正這個問題,請檢查檔案所屬 Google Workspace 網域的共用設定。這類設定可能會禁止與網域外部人員共用檔案,或無法共用共用雲端硬碟。
401 錯誤
這些錯誤表示要求未包含有效的存取權杖。
authError
您使用的存取權杖已過期或無效時,就會發生這個錯誤。這個錯誤也可能是要求範圍缺少授權所致。以下 JSON 範例代表這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization",
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
如要修正這個錯誤,請使用永久更新權杖重新整理存取權杖。如果這項操作失敗,請按照「選擇 Google Drive API 範圍」中的說明,引導使用者完成 OAuth 流程。
403 錯誤
這些錯誤表示已超過用量限制,或使用者未具備適當權限。如要判斷原因,請評估傳回的 JSON 的 reason
欄位。
如要瞭解 Drive API 限制,請參閱使用限制。如要瞭解雲端硬碟資料夾限制,請參閱檔案和資料夾限制。
activeItemCreationLimitExceeded
如果超出單一帳戶建立的項目數量上限,就會發生 activeItemCreationLimitExceeded
錯誤。每位使用者最多可以擁有 5 億個帳戶建立項目。詳情請參閱「使用者項目限制」。
{
"error": {
"errors": [
{
"domain": "global",
"reason": "activeItemCreationLimitExceeded",
"message": "This account has exceeded the creation limit of 500 million items. To create more items, permanently delete some items."
}
],
"code": 403,
"message": "This account has exceeded the creation limit of 500 million items. To create more items, permanently delete some items."
}
}
如何修正這項錯誤:
通知使用者雲端硬碟禁止帳戶建立超過 5 億個項目。
如果使用者必須在相同的帳戶中建立項目,請指示他們永久刪除部分物件。否則,他們可以使用另一個已經符合要求的帳戶。
appNotAuthorizedToFile
這表示應用程式不在該檔案的 ACL 中時,就會發生這個錯誤。這項錯誤會導致使用者無法透過應用程式開啟檔案。以下 JSON 範例代表這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "appNotAuthorizedToFile",
"message": "The user has not granted the app {appId} {verb} access to the file {fileId}."
}
],
"code": 403,
"message": "The user has not granted the app {appId} {verb} access to the file {fileId}."
}
}
如要修正這個錯誤,請嘗試下列任一方法:
- 開啟 Google 雲端硬碟挑選工具,並提示使用者開啟檔案。
- 引導使用者透過應用程式雲端硬碟 UI 中的「Open with」(開啟方式) 內容選單開啟檔案。
- 使用
files.get
方法檢查files
資源中的isAppAuthorized
欄位,驗證應用程式是否已建立或開啟檔案。
cannotModifyInheritedTeamDrivePermission
當使用者嘗試修改共用雲端硬碟內項目的沿用權限時,就會發生這個錯誤。您無法從共用雲端硬碟中的項目移除沿用的權限。以下 JSON 範例代表這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "cannotModifyInheritedTeamDrivePermission",
"message": "Cannot update or delete an inherited permission on a shared drive item."
}
],
"code": 403,
"message": "Cannot update or delete an inherited permission on a shared drive item."
}
}
如要修正這個問題,使用者必須調整沿用其直接或間接父項項目的權限。詳情請參閱「權限傳播」。您也可以擷取 permissions.permissionDetails
資源,查看是否沿用或直接套用這個共用雲端硬碟項目的權限。
dailyLimitExceeded
達到專案的 API 限制時,就會發生這個錯誤。以下 JSON 範例呈現了這個錯誤:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceeded",
"message": "Daily Limit Exceeded"
}
],
"code": 403,
"message": "Daily Limit Exceeded"
}
}
如果應用程式擁有者設定了配額限制來限制特定資源的用量,就會顯示這個錯誤。如要修正這個錯誤,請移除「每日查詢」配額的所有用量上限。
domainPolicy
如果使用者網域的政策不允許應用程式存取雲端硬碟,就會發生這個錯誤。以下 JSON 範例表示這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "domainPolicy",
"message": "The domain administrators have disabled Drive apps."
}
],
"code": 403,
"message": "The domain administrators have disabled Drive apps."
}
}
如何修正這項錯誤:
- 通知使用者,網域不允許應用程式存取雲端硬碟中的檔案。
- 指示使用者與網域管理員聯絡,要求取得應用程式的存取權。
fileOwnerNotMemberOfTeamDrive
當嘗試將檔案移至共用雲端硬碟,且檔案擁有者不是成員時,就會發生這個錯誤。以下 JSON 範例是這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "fileOwnerNotMemberOfTeamDrive",
"message": "Cannot move a file into a shared drive as a writer when the owner of the file is not a member of that shared drive."
}
],
"code": 403,
"message": "Cannot move a file into a shared drive as a writer when the owner of the file is not a member of that shared drive."
}
}
如何修正這項錯誤:
將這位成員加入與
role=owner
的共用雲端硬碟。詳情請參閱「共用檔案、資料夾和雲端硬碟」。將檔案加入共用雲端硬碟。詳情請參閱「建立並填入資料夾」。
fileWriterTeamDriveMoveInDisabled
如果網域管理員不允許擁有 role=writer
的使用者將項目移至共用雲端硬碟,就會發生這個錯誤。使用者嘗試移動項目的權限比目標共用雲端硬碟允許的權限少。以下 JSON 範例是這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "fileWriterTeamDriveMoveInDisabled",
"message": "The domain administrator has not allowed writers to move items into a shared drive."
}
],
"code": 403,
"message": "The domain administrator has not allowed writers to move items into a shared drive."
}
}
如要修正這個錯誤,請對來源和目的地共用雲端硬碟使用相同的管理員使用者帳戶。
insufficientFilePermissions
如果使用者沒有檔案的寫入權限,且應用程式嘗試修改檔案,就會發生這個錯誤。下列 JSON 範例代表這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "insufficientFilePermissions",
"message": "The user does not have sufficient permissions for file {fileId}."
}
],
"code": 403,
"message": "The user does not have sufficient permissions for file {fileId}."
}
}
如要修正錯誤,請指示使用者與檔案擁有者聯絡,並要求編輯權限。您也可以檢查 files.get
方法所擷取中繼資料中的使用者存取層級,並在缺少權限時顯示唯讀 UI。
myDriveHierarchyDepthLimitExceeded
如果超過巢狀資料夾層級的數量限制,就會發生 myDriveHierarchyDepthLimitExceeded
錯誤。使用者的「我的雲端硬碟」最多只能包含 100 層的巢狀資料夾。詳情請參閱資料夾深度限制。
{
"error": {
"errors": [
{
"domain": "global",
"reason": "myDriveHierarchyDepthLimitExceeded",
"message": "Your My Drive can't contain more than 100 levels of folders. For details, see https://developers.google.com/drive/api/guides/handle-errors#nested-folder-levels."
}
],
"code": 403,
"message": "Your My Drive can't contain more than 100 levels of folders. For details, see https://developers.google.com/drive/api/guides/handle-errors#nested-folder-levels."
}
}
如何修正這項錯誤:
- 請通知使用者,雲端硬碟會禁止將資料夾置於超過 100 層的層級。
- 如果使用者必須建立另一個巢狀資料夾,請指示使用者將對應的上層資料夾重新整理至少於 100 層,或使用其他符合需求的父項資料夾。
numChildrenInNonRootLimitExceeded
超過資料夾子項 (資料夾、檔案和捷徑) 數量限制時,就會發生這個錯誤。直接資料夾中的資料夾、檔案及捷徑項目數量上限為 500,000 個。子資料夾中的巢狀項目不會計入 500,000 個項目的限制。如要進一步瞭解雲端硬碟資料夾限制,請參閱 Google 雲端硬碟中的資料夾限制。
以下 JSON 範例代表這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "numChildrenInNonRootLimitExceeded",
"message": "The limit for this folder's number of children (files and folders) has been exceeded."
}
],
"code": 403,
"message": "The limit for this folder's number of children (files and folders) has been exceeded."
}
}
如要修正這個錯誤,請嘗試下列任一方法:
- 請通知使用者,雲端硬碟會防止內含超過 500,000 個項目的資料夾。
- 如果使用者必須在完整資料夾中加入更多項目,請指示使用者重新整理資料夾,納入少於 500,000 個項目,或者使用已包含較少項目的類似資料夾。
rateLimitExceeded
達到專案頻率限制時,就會發生這個錯誤。這項限制會因要求類型而異。下列 JSON 範例代表這個錯誤:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"message": "Rate Limit Exceeded",
"reason": "rateLimitExceeded",
}
],
"code": 403,
"message": "Rate Limit Exceeded"
}
}
如要修正這個錯誤,請嘗試下列任一方法:
sharingRateLimitExceeded
當使用者達到共用上限,且通常與電子郵件限制相關聯,就會發生這個錯誤。以下 JSON 範例是這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"message": "Rate limit exceeded. User message: \"These item(s) could not be shared because a rate limit was exceeded: filename",
"reason": "sharingRateLimitExceeded",
}
],
"code": 403,
"message": "Rate Limit Exceeded"
}
}
如何修正這項錯誤:
- 分享大量檔案時不要傳送電子郵件。
- 如果某位使用者代表某個 Google Workspace 帳戶的許多使用者提出多次要求,請考慮使用
quotaUser
參數具有全網域委派功能的服務帳戶。
storageQuotaExceeded
使用者達到儲存空間上限時,就會發生這項錯誤。以下 JSON 範例呈現了這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"message": "The user's Drive storage quota has been exceeded.",
"reason": "storageQuotaExceeded",
}
],
"code": 403,
"message": "The user's Drive storage quota has been exceeded."
}
}
如何修正這項錯誤:
查看您的雲端硬碟儲存空間上限。詳情請參閱 Google Workspace 儲存空間和上傳限制。
teamDriveFileLimitExceeded
如果使用者嘗試超過共用雲端硬碟的項目嚴格限制,就會發生這個錯誤。使用者共用雲端硬碟中的每個資料夾上限為 400,000 個項目,包括檔案、資料夾和捷徑。這項限制是以項目數量為準,而非儲存空間使用量。詳情請參閱「Google 雲端硬碟的共用雲端硬碟限制」一文。
以下 JSON 範例代表這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "teamDriveFileLimitExceeded",
"message": "The file limit for this shared drive has been exceeded."
}
],
"code": 403,
"message": "The file limit for this shared drive has been exceeded."
}
}
如要修正這個錯誤,請減少共用雲端硬碟中的項目數量。含有過多檔案的共用雲端硬碟可能很難整理及搜尋。
teamDriveMembershipRequired
如果使用者嘗試存取自己不是成員的共用雲端硬碟,就會發生這個錯誤。以下 JSON 範例代表這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "teamDriveMembershipRequired",
"message": "The attempted action requires shared drive membership."
}
],
"code": 403,
"message": "The attempted action requires shared drive membership."
}
}
如要修正這個錯誤,請嘗試下列任一方法:
teamDrivesFolderMoveInNotSupported
如果使用者嘗試將資料夾從「我的雲端硬碟」移至共用雲端硬碟,就會發生這個錯誤。下列 JSON 範例代表這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "teamDrivesFolderMoveInNotSupported",
"message": "Moving folders into shared drives is not supported."
}
],
"code": 403,
"message": "Moving folders into shared drives is not supported."
}
}
如要修正這個錯誤,請嘗試下列任一方法:
使用 Drive API,將資料夾中的個別項目移至共用雲端硬碟。設定
supportsAllDrives=true
參數,表示支援「我的雲端硬碟」和共用雲端硬碟。如果您需要將資料夾移至共用雲端硬碟,請使用雲端硬碟 UI。詳情請參閱「以管理員身分將資料夾移至共用雲端硬碟」。
teamDrivesParentLimit
使用者嘗試為共用雲端硬碟中的項目新增多個父項時,就會發生這個錯誤。以下 JSON 範例代表這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "teamDrivesParentLimit",
"message": "A shared drive item must have exactly one parent."
}
],
"code": 403,
"message": "A shared drive item must have exactly one parent."
}
}
如要修正這個錯誤,請使用雲端硬碟捷徑為檔案新增多個連結。雖然捷徑只能有一個父項,但捷徑檔案可以複製到額外位置。詳情請參閱「建立雲端硬碟檔案的捷徑」。
UrlLeaseLimitExceeded
嘗試透過應用程式儲存 Google Play 遊戲資料時,就會發生這項錯誤。以下 JSON 範例代表這個錯誤:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "UrlLeaseLimitExceeded",
"message": "Too many pending uploads for this snapshot. Please finish or cancel some before creating more."
}
],
"code": 403,
"message": "Too many pending uploads for this snapshot. Please finish or cancel some before creating more."
}
}
如要修正這個錯誤,請先完成或取消快照的上傳作業,再建立其他快照。
userRateLimitExceeded
這個錯誤發生在每位使用者可擁有的限制時。這可能是 Google Cloud 控制台的限制,或是雲端硬碟後端的限制。以下 JSON 範例代表這個錯誤:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "userRateLimitExceeded",
"message": "User Rate Limit Exceeded"
}
],
"code": 403,
"message": "User Rate Limit Exceeded"
}
}
如要修正這個錯誤,請嘗試下列任一方法:
- 如要提高 Google Cloud 專案中的每位使用者配額,詳情請參閱要求提高配額的相關說明。
如果某位使用者代表某個 Google Workspace 帳戶的許多使用者提出多次要求,請考慮使用
quotaUser
參數具有全網域委派功能的服務帳戶。請使用指數輪詢重試要求。
如要瞭解 Drive API 限制,請參閱使用限制。
404 錯誤
這些錯誤表示要求的資源無法存取或不存在。
notFound
如果使用者沒有檔案的讀取權限,或是檔案不存在,就會發生這個錯誤。以下 JSON 範例代表這個錯誤:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "File not found {fileId}"
}
],
"code": 404,
"message": "File not found: {fileId}"
}
}
如何修正這項錯誤:
- 如果檔案位於共用雲端硬碟中,且您使用
files.get
方法,請確認supportsAllDrives
查詢參數已設為true
。 - 通知使用者,他們沒有檔案的讀取權限,或是檔案不存在。
- 指示使用者與檔案擁有者聯絡,並要求取得檔案權限。
429 錯誤
這些錯誤表示傳送至 API 的要求次數過多,
rateLimitExceeded
當使用者在指定時間內傳送過多要求時,就會發生這個錯誤。以下 JSON 範例代表這個錯誤:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "rateLimitExceeded",
"message": "Rate Limit Exceeded"
}
],
"code": 429,
"message": "Rate Limit Exceeded"s
}
}
如要修正這個錯誤,請使用指數輪詢重試要求。
500、502、503、504 錯誤
處理要求時發生未預期的伺服器錯誤時,就會發生這些錯誤。各種問題可能會導致這類錯誤,包括要求的時間與其他要求重疊,或是要求執行不支援的操作,例如嘗試更新 Google 協作平台中的單一頁面 (而非整個網站) 的權限。
以下列出 5xx 錯誤:
- 500 後端錯誤
- 502 閘道錯誤
- 503 服務無法使用
- 504 閘道逾時
如要修正這個錯誤,請使用指數輪詢重試要求。