解决错误

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 字段并相应地调整您的代码。

illegalKeepForeverModification

当尝试将标记为“Keep Forever”的 Blob 文件修订版本设置为 false 时,会发生此错误。以下 JSON 示例表示此错误:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "illegalKeepForeverModification",
    "message": "Bad Request. Cannot update a revision to false that is marked as keepForever."
   }
  ],
  "code": 400,
  "message": "Bad Request. Cannot update a revision to false that is marked as keepForever."
 }
}

如需修复此错误,请永久删除 Blob 文件修订版本以移除“Keep Forever”设置。

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 流程。

fileNotDownloadable

当您尝试对 Google Workspace 文档使用带有 alt=media 网址参数的 revisions.get 方法时,会发生此错误。以下 JSON 示例表示此错误:

{
  "error": {
    "errors": [
      {
        "domain": "global",
        "reason": "fileNotDownloadable",
        "message": "Only files with binary content can be downloaded. Use Export with Docs Editors files."
      }
    ],
    "code": 403,
    "message": "Only files with binary content can be downloaded. Use Export with Docs Editors files."
  }
}

如需修复此错误,请尝试以下任一操作:

  • 如果您想查看特定修订版本的元数据(例如 MIME 类型),请移除 alt=media 网址参数。
  • 使用 files.export 方法导出 Google Workspace 文档字节内容。如需了解详情,请参阅导出 Google Workspace 文档 内容

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."
 }
}

如需修复此错误,请执行以下操作:

  1. 告知用户,云端硬盘禁止账号创建超过 5 亿个内容。

  2. 如果用户必须在此同一账号中创建内容,请指示他们永久删除一些对象。否则,他们可以使用已满足要求的其他账号。

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}."
  }
}

如需修复此错误,请尝试以下任一操作:

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 资源,以查看此共享云端硬盘内容的权限是继承的还是直接应用的。

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."
  }
}

如需修复此错误,请执行以下操作:

  1. 告知用户,网域不允许您的应用访问云端硬盘中的文件。
  2. 指示用户与网域管理员联系,请求为您的应用授予访问权限。

downloadRestrictedForRevision

当用户无法下载 Blob 文件修订版本时,会发生此错误。以下 JSON 示例表示此错误:

{
  "error": {
    "errors": [
      {
        "domain": "global",
        "reason": "download_restricted_for_revision",
        "message": "This revision cannot be downloaded by the authenticated user."
      }
    ],
    "code": 403,
    "message": "This revision cannot be downloaded by the authenticated user."
  }
}

如需修复此错误,请告知用户,只有当 Blob 文件修订版本标记为“Keep Forever”时,才能下载。如需了解详情,请参阅 指定要保存的修订版本,以防自动 删除

fileNotExportable

当用户尝试导出 Google Vids 文件时,会发生此错误。以下 JSON 示例表示此错误:

{
  "error": {
    "errors": [
      {
        "domain": "global",
        "reason": "fileNotExportable",
        "message": "Google Vids does not support files.export. Use files.download with Vids files."
      }
    ],
    "code": 403,
    "message": "Google Vids does not support files.export. Use files.download with Vids files."
  }
}

如需修复此错误,请告知用户,必须使用 files.download 方法下载 Google Vids 文件,因为不支持 files.export 方法。 如需了解详情,请参阅下载和导出文件

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."
  }
}

如需修复此错误,请执行以下操作:

  1. 使用 role=owner 将成员添加到共享云端硬盘。如需了解详情, 请参阅共享文件、文件夹和云端硬盘

  2. 将文件添加到共享云端硬盘。如需了解详情,请参阅创建和 填充文件夹

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

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/workspace/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/workspace/drive/api/guides/handle-errors#nested-folder-levels."
 }
}

如需修复此错误,请执行以下操作:

  1. 告知用户,云端硬盘禁止将文件夹放置在超过 100 级的深度。
  2. 如果用户必须创建另一个嵌套文件夹,请指示他们重新整理目标父文件夹,使其深度小于 100 级,或使用已满足要求的其他父文件夹。

numChildrenInNonRootLimitExceeded

当文件夹的子项(文件夹、文件和快捷方式)数量超出限制时,会发生此错误。文件夹中直接包含的文件夹、文件和快捷方式的数量上限为 50 万个。嵌套在子文件夹中的内容不计入这 50 万个内容的限制。如需详细了解 云端硬盘文件夹限制,请参阅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."
 }
}

如需修复此错误,请尝试以下任一操作:

  • 告知用户,云端硬盘禁止文件夹包含超过 50 万个内容。
  • 如果用户必须向已满的文件夹添加更多内容,请指示他们重新整理文件夹,使其包含的内容少于 50 万个,或使用已包含较少内容的类似文件夹。

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"
 }
}

如需修复此错误,请执行以下操作:

  1. 共享大量文件时,请勿发送电子邮件。
  2. 如果一位用户代表 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."
 }
}

如需修复此错误,请执行以下操作:

  1. 查看您的云端硬盘账号存储空间限制。如需了解详情,请参阅 Google Workspace 存储空间和上传 限制

  2. 管理云端硬盘、Gmail 和 Google 相册中的存储空间。

  3. 购买更多 Google 存储空间

teamDriveFileLimitExceeded

当用户尝试超出共享云端硬盘的严格内容限制时,会发生此错误。用户共享云端硬盘中的每个文件夹的内容数量上限为 50 万个,包括文件、文件夹和快捷方式。此限制针对的是内容数量,而不是存储空间使用情况。如需了解详情,请参阅 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."
  }
}

如需修复此错误,请减少共享云端硬盘中的内容数量。如果共享云端硬盘中的文件过多,则可能难以进行整理和搜索。

teamDriveHierarchyTooDeep

当共享云端硬盘嵌套文件夹级别的数量超出限制时,会发生 teamDriveHierarchyTooDeep 错误。用户的共享云端硬盘包含的嵌套文件夹不能超过 100 级。如需了解详情,请参阅 文件夹深度限制

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "teamDriveHierarchyTooDeep",
    "message": "The shared drive hierarchy depth will exceed the limit."
   }
  ],
  "code": 403,
  "message": "The shared drive hierarchy depth will exceed the limit."
 }
}

如需修复此错误,请执行以下操作:

  1. 告知用户,共享云端硬盘禁止将文件夹放置在超过 100 级的深度。
  2. 如果用户必须创建另一个嵌套文件夹,请指示他们重新整理目标父文件夹,使其深度小于 100 级,或使用已满足要求的其他父文件夹。

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."
  }
}

如需修复此错误,请尝试以下任一操作:

  1. 请共享云端硬盘的管理员为您添加执行所需操作的相应权限。

  2. 查看云端硬盘的角色和 权限,了解哪些人可以访问和管理 共享云端硬盘。如需了解有关访问权限级别的更多信息,请参阅 创建共享 云端硬盘

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 参数以表示同时支持“我的云端硬盘”和共享云端硬盘。

  • 如果您必须将文件夹移至共享云端硬盘,请使用云端硬盘界面。如需了解详情,请参阅以管理员身份将文件夹移至共享 云端硬盘

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"
 }
}

如需修复此错误,请尝试以下任一操作:

如需了解 Drive API 限制,请参阅使用限制

404 错误

这些错误表示请求的资源无法访问或不存在。

notFound

当用户没有文件的读取权限,或者文件不存在时,会发生此错误。以下 JSON 示例表示此错误:

{
  "error": {
    "errors": [
      {
        "domain": "global",
        "reason": "notFound",
        "message": "File not found {fileId}"
      }
    ],
    "code": 404,
    "message": "File not found: {fileId}"
  }
}

如需修复此错误,请执行以下操作:

  1. 如果文件位于共享云端硬盘中,并且您使用的是 files.get 方法,请确保 supportsAllDrives 查询参数设置为 true
  2. 告知用户,他们没有文件的读取权限,或者文件不存在。
  3. 指示用户与文件所有者联系并请求文件权限。

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 Bad Gateway
  • 503 Service Unavailable
  • 504 Gateway Timeout

如需修复此错误,请使用指数退避算法 重试请求。