Drive API v2 与 v3 比较指南
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
最新的 Google 云端硬盘 API 版本为 v3。v3 中的性能更好,因为搜索仅返回部分字段。除非您需要 v2 集合,否则请使用当前版本。如果您使用的是 v2,请考虑迁移到 v3。如需迁移,请参阅迁移到 Drive API v3。如需查看版本差异的完整列表,请参阅 Drive API v2 和 v3 比较参考文档。
如果您想继续使用 v2,请参阅 Drive API v2 指南修订版,了解 v3 指南中的一些说明必须如何针对 v2 开发者进行修订。
如需详细了解 Drive API v3 的改进,您可以观看以下视频,其中 Google 工程师讨论了新的 API 设计。
V3 改进
为了优化性能并降低 API 行为的复杂性,v3 在之前的 API 版本的基础上进行了以下改进:
- 默认情况下,搜索文件和共享云端硬盘不会返回完整资源,只会返回常用字段的子集。如需详细了解
fields
,请参阅 files.list
方法和 drives.list
方法。
- 现在,几乎所有返回响应的方法都需要
fields
参数。如需查看需要 fields
的所有方法的列表,请参阅
Drive API 参考文档。
- 移除了具有重复功能的资源。以下是一些示例:
files.list
方法可实现与 Children
和 Parents
集合相同的功能,因此已从 v3 中移除。
- 移除了
Realtime.*
方法。
- 默认情况下,搜索中不会返回应用数据。在 v2 中,您可以设置
drive.appdata
范围,它会返回 files.list
方法和 changes.list
方法中的应用数据,但会降低性能。在 v3 中,您需要设置 drive.appdata
范围,同时设置查询参数 spaces=appDataFolder
以请求应用数据。
- 所有更新操作都使用 PATCH 而不是 PUT。
- 如需导出 Google 文档,请使用
files.export
方法。
changes.list
方法的行为有所不同。请使用不透明的分页令牌,而不是更改 ID。如需轮询更改集合,请先调用 changes.getStartPageToken
方法获取初始值。对于后续查询,changes.list
方法会返回 newStartPageToken
值。
- 更新方法现在会拒绝指定了不可写入字段的请求。
about
资源中的 v2 exportFormats
和 importFormats
字段是允许的导入或导出格式的列表。在 v3 中,它们是可能的目标到所有受支持的导入或导出的 MIME 类型映射。
- v2 中的
appdata
和 appfolder
别名在 v3 中现在为 appDataFolder
。
properties
资源已从 v3 中移除。files
资源具有包含真实键值对的 properties
字段。properties
字段包含公共属性,appProperties
字段包含私有属性,因此不需要公开范围字段。
files
资源中的 modifiedTime
字段会更新上次有人修改文件的时间。在 v2 中,只有在设置了 setModifiedDate
字段的情况下,modifiedDate
字段才能在更新时发生变化。
files
资源中的 viewedByMeTime
字段不会自动更新。
- 如需导入 Google 文档格式,请在资源正文中设置适当的目标
mimeType
。在 v2 中,您需要设置 ?convert=true
。
- 如果格式不受支持,导入操作会返回 400 错误。
- 读者和评论者无法查看权限。
- 移除了权限的
me
别名。
- 部分功能之前是请求资源的一部分,现在则作为请求参数提供。例如:
- 在 v2 中,您可以使用
children.delete
从父文件夹中移除子文件。
- 在 v3 中,您可以在网址中使用
?removeParents=parent_id
,并在子级上使用 files.update
。
其他差异
v3 中的字段和参数名称有所不同。部分示例如下:
name
属性取代了 files
资源中的 title
。
Time
是所有日期和时间字段的后缀,而不是 Date
。
- 列表操作不使用
items
字段来包含结果集。资源类型为结果提供了一个字段(例如 files
或 changes
)。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[],[],null,["# Drive API v2 and v3 comparison guide\n\nThe latest Google Drive API version is v3. The performance in v3 is better because\nsearches only return a subset of fields. Use the current version unless you need\nthe [v2](/workspace/drive/api/v2/reference) collection. If you're using v2, consider\nmigrating to v3. To migrate, see [Migrate to Drive API v3](/workspace/drive/api/guides/migrate-to-v3). For a complete list of version differences, see\nthe [Drive API v2 and v3 comparison\nreference](/workspace/drive/api/guides/v2-to-v3-reference).\n\nIf you want to continue to use v2, see the [Guide to Drive API v2](/workspace/drive/api/guides/v2-guide) amendment to learn how some instructions in the v3\nguides must be amended for v2 developers.\n\nTo learn more about Drive API v3 improvements, you can watch the\nfollowing video by Google engineers discussing the new API design. \n\nV3 improvements\n---------------\n\nTo optimize performance and reduce API behavior complexity, v3 provides these\nimprovements over the previous API version:\n\n- Searches for files and shared drives don't return full resources by default, only a subset of commonly used fields gets returned. For more details on `fields`, see the [`files.list`](/workspace/drive/api/v3/reference/files/list) method and the [`drives.list`](/workspace/drive/api/v3/reference/drives/list) method.\n- Almost all methods that return a response now require the `fields` parameter. For a list of all methods requiring `fields`, see the [Drive API reference](/workspace/drive/api/v3/reference).\n- Resources that have duplicate capabilities were removed. Some examples:\n - The `files.list` method accomplishes the same functionality as the `Children` and `Parents` collections, so they're removed from v3.\n - The `Realtime.*` methods have been removed.\n- App Data isn't returned by default in searches. In v2, you can set the `drive.appdata` scope, and it returns application data from the `files.list` method and the [`changes.list`](/workspace/drive/api/v2/reference/changes/list) method, but it slows performance. In v3, you set the `drive.appdata` scope, and also set the query parameter `spaces=appDataFolder` to request application data.\n- All update operations use PATCH instead of PUT.\n- To export Google Documents, use the [`files.export`](/workspace/drive/api/v2/reference/files/export) method.\n- The `changes.list` method behavior is different. Instead of change IDs, use opaque page tokens. To poll the change collection, first call the [`changes.getStartPageToken`](/workspace/drive/api/v2/reference/changes/getStartPageToken) method for the initial value. For subsequent queries, the `changes.list` method returns the `newStartPageToken` value.\n- Update methods now reject requests that specify non-writable fields.\n- The v2 `exportFormats` and `importFormats` fields in the [`about`](/workspace/drive/api/reference/rest/v3/about) resource are lists of allowable import or export formats. In v3, they're MIME type maps of possible targets to all supported imports or exports.\n- The v2 `appdata` and `appfolder` aliases are now `appDataFolder` in v3.\n- The `properties` resource is removed from v3. The [`files`](/workspace/drive/api/v3/reference/files) resource has the `properties` field that contains true key-value pairs. The `properties` field contains public properties, and the `appProperties` field contains private properties, so the visibility field isn't needed.\n- The `modifiedTime` field in the `files` resource updates the last time anyone modified the file. In v2, the `modifiedDate` field was only mutable on update if you set the `setModifiedDate` field.\n- The `viewedByMeTime` field in the `files` resource doesn't automatically update.\n- To import Google Docs formats, you set the appropriate target `mimeType` in the resource body. In v2, you set `?convert=true`.\n- Import operations return a 400 error if the format isn't supported.\n- Readers and commenters can't view permissions.\n- The `me` alias for permissions is removed.\n- Some functionality was available as part of the request resource but is instead available as a request parameter. For example:\n - In v2, you can use `children.delete` to remove a child file from a parent folder.\n - In v3, you use`files.update` on the child with `?removeParents=parent_id` in the URL.\n\nOther differences\n-----------------\n\nFields and parameter names are different in v3. Some examples include:\n\n- The `name` property replaces `title` in the `files` resource.\n- `Time` is the suffix for all date and time fields instead of `Date`.\n- List operations don't use the `items` field to contain the result set. The resource type provides a field for the results (such as `files` or `changes`)."]]