Drive API v2 和 v3 比較指南
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
最新版 Google 雲端硬碟 API 為 v3。第 3 版的效能較佳,因為搜尋只會傳回部分欄位。除非需要 v2 集合,否則請使用目前版本。如果您使用第 2 版,請考慮遷移至第 3 版。如要遷移,請參閱「遷移至 Drive API v3」。如需完整的版本差異清單,請參閱 Drive API v2 和 v3 比較參考資料。
如要繼續使用第 2 版,請參閱「Drive API 第 2 版指南」修訂內容,瞭解第 3 版指南中的部分操作說明,如何為第 2 版開發人員進行修訂。
如要進一步瞭解 Drive API v3 的改良之處,請觀看下列影片,聽取 Google 工程師討論新版 API 設計。
V3 改善項目
為提升效能及簡化 API 行為,v3 相較於舊版 API 有下列改良之處:
- 根據預設,搜尋檔案和共用雲端硬碟不會傳回完整資源,只會傳回常用欄位的子集。如要進一步瞭解
fields
,請參閱 files.list
方法和 drives.list
方法。
- 現在,幾乎所有會傳回回應的方法都需要
fields
參數。如要查看需要 fields
的所有方法清單,請參閱
Drive API 參考資料。
- 已移除功能重複的資源。舉例來說:
files.list
方法可達成與 Children
和 Parents
集合相同的用途,因此已從第 3 版中移除。
- 已移除
Realtime.*
方法。
- 根據預設,搜尋結果不會顯示應用程式資料。在第 2 版中,您可以設定
drive.appdata
範圍,並從 files.list
方法和 changes.list
方法傳回應用程式資料,但這會降低效能。在第 3 版中,您會設定 drive.appdata
範圍,並設定查詢參數 spaces=appDataFolder
來要求應用程式資料。
- 所有更新作業都會使用 PATCH,而非 PUT。
- 如要匯出 Google 文件,請使用
files.export
方法。
changes.list
方法的行為有所不同。請改用不透明網頁權杖,而非變更 ID。如要輪詢變更集合,請先呼叫 changes.getStartPageToken
方法取得初始值。後續查詢時,changes.list
方法會傳回 newStartPageToken
值。
- 更新方法現在會拒絕指定不可寫入欄位的要求。
about
資源中的 v2 exportFormats
和 importFormats
欄位是允許匯入或匯出格式的清單。在第 3 版中,這些是可能目標的 MIME 類型對應,適用於所有支援的匯入或匯出作業。
- v2 的
appdata
和 appfolder
別名現在是 v3 的 appDataFolder
。
- 系統會從 v3 移除
properties
資源。files
資源具有 properties
欄位,其中包含實際的鍵/值組合。properties
欄位包含公開屬性,appProperties
欄位包含私人屬性,因此不需要瀏覽權限欄位。
files
資源中的 modifiedTime
欄位會更新檔案上次修改的時間。在第 2 版中,只有在設定 setModifiedDate
欄位時,才能在更新時變更 modifiedDate
欄位。
files
資源中的 viewedByMeTime
欄位不會自動更新。
- 如要匯入 Google 文件格式,請在資源主體中設定適當的目標
mimeType
。在第 2 版中,您會設定 ?convert=true
。
- 如果格式不受支援,匯入作業會傳回 400 錯誤。
- 讀者和加註者無法查看權限。
- 移除權限的
me
別名。
- 部分功能原本是要求資源的一部分,但現在改為要求參數。例如:
- 在第 2 版中,您可以使用
children.delete
從上層資料夾移除子項檔案。
- 在第 3 版中,您會在網址中使用
files.update
,對子項使用 ?removeParents=parent_id
。
其他差異
v3 的欄位和參數名稱不同。例如:
name
屬性會取代 files
資源中的 title
。
- 所有日期和時間欄位的後置字串都是
Time
,而非 Date
。
- 清單作業不會使用
items
欄位來包含結果集。資源類型會提供結果的欄位 (例如 files
或 changes
)。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間: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`)."]]