คู่มือเปรียบเทียบ API ไดรฟ์ v2 และ v3
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Google ไดรฟ์ API เวอร์ชันล่าสุดคือ v3 ประสิทธิภาพใน v3 ดีกว่าเนื่องจาก
การค้นหาจะแสดงเฉพาะฟิลด์ย่อย ใช้เวอร์ชันปัจจุบัน เว้นแต่คุณจะต้องใช้คอลเล็กชัน v2 หากคุณใช้ v2 ให้พิจารณา
ย้ายข้อมูลไปยัง v3 หากต้องการย้ายข้อมูล โปรดดูย้ายข้อมูลไปยัง Drive API v3 ดูรายการความแตกต่างของเวอร์ชันทั้งหมดได้ที่เอกสารอ้างอิงการเปรียบเทียบ Drive API v2 และ v3
หากต้องการใช้เวอร์ชัน 2 ต่อไป โปรดดูการแก้ไขคำแนะนำสำหรับ Drive API เวอร์ชัน 2 เพื่อดูวิธีแก้ไขคำสั่งบางอย่างในคำแนะนำเวอร์ชัน 3
สำหรับนักพัฒนาแอปเวอร์ชัน 2
หากต้องการดูข้อมูลเพิ่มเติมเกี่ยวกับการปรับปรุง Drive API v3 คุณสามารถดูวิดีโอต่อไปนี้ที่วิศวกรของ Google พูดถึงการออกแบบ API ใหม่
การปรับปรุง V3
เวอร์ชัน 3 มีการปรับปรุงต่อไปนี้จาก API เวอร์ชันก่อนหน้าเพื่อเพิ่มประสิทธิภาพและลดความซับซ้อนของลักษณะการทำงานของ 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
จะแตกต่างกัน ให้ใช้โทเค็นหน้าเว็บแบบทึบแทนการเปลี่ยนรหัส หากต้องการสำรวจการเปลี่ยนแปลง ให้เรียกใช้เมธอด
changes.getStartPageToken
สำหรับค่าเริ่มต้นก่อน สำหรับการค้นหาครั้งต่อๆ ไป เมธอด changes.list
จะแสดงค่า newStartPageToken
- ตอนนี้เมธอดอัปเดตจะปฏิเสธคำขอที่ระบุช่องที่เขียนไม่ได้
- ฟิลด์ v2
exportFormats
และ importFormats
ในแหล่งข้อมูล about
คือรายการรูปแบบการนำเข้าหรือส่งออกที่อนุญาต ใน v3 จะเป็นแผนที่ประเภท MIME ของ
เป้าหมายที่เป็นไปได้สำหรับการนำเข้าหรือส่งออกที่รองรับทั้งหมด
- ตอนนี้ชื่อแทน
appdata
และ appfolder
ใน v2 คือ appDataFolder
ใน v3
- ระบบจะนำทรัพยากร
properties
ออกจาก v3 ทรัพยากร
files
มีฟิลด์ properties
ซึ่งมีคู่คีย์-ค่าจริง ฟิลด์ properties
มีพร็อพเพอร์ตี้สาธารณะ และฟิลด์ appProperties
มีพร็อพเพอร์ตี้ส่วนตัว จึงไม่จำเป็นต้องมีฟิลด์ระดับการแชร์
- ฟิลด์
modifiedTime
ในทรัพยากร files
จะอัปเดตเวลาล่าสุด
ที่มีการแก้ไขไฟล์ ใน v2 ช่อง modifiedDate
จะเปลี่ยนแปลงได้
เมื่ออัปเดตเท่านั้น หากคุณตั้งค่าช่อง setModifiedDate
- ฟิลด์
viewedByMeTime
ในทรัพยากร files
จะไม่อัปเดตโดยอัตโนมัติ
- หากต้องการนำเข้ารูปแบบ Google เอกสาร ให้ตั้งค่าเป้าหมายที่เหมาะสม
mimeType
ในเนื้อหาของทรัพยากร ใน v2 คุณตั้งค่า ?convert=true
- การดำเนินการนำเข้าจะแสดงข้อผิดพลาด 400 หากไม่รองรับรูปแบบ
- ผู้อ่านและผู้แสดงความคิดเห็นจะดูสิทธิ์ไม่ได้
- ระบบจะนำชื่อแทน
me
สำหรับสิทธิ์ออก
- ฟังก์ชันบางอย่างเคยพร้อมใช้งานเป็นส่วนหนึ่งของทรัพยากรคำขอ แต่ตอนนี้พร้อมใช้งานเป็นพารามิเตอร์คำขอแทน เช่น
- ใน v2 คุณสามารถใช้
children.delete
เพื่อนำไฟล์ย่อยออกจาก
โฟลเดอร์หลักได้
- ใน v3 คุณใช้
files.update
กับองค์ประกอบย่อยที่มี
?removeParents=parent_id
ใน URL
ความแตกต่างอื่นๆ
ฟิลด์และชื่อพารามิเตอร์ใน v3 จะแตกต่างกัน ตัวอย่างเช่น
- พร็อพเพอร์ตี้
name
จะแทนที่ title
ในแหล่งข้อมูล files
Time
เป็นคำต่อท้ายสำหรับช่องวันที่และเวลาทั้งหมดแทน Date
- การดำเนินการในรายการจะไม่ใช้ฟิลด์
items
เพื่อเก็บชุดผลลัพธ์
ประเภททรัพยากรมีช่องสำหรับผลลัพธ์ (เช่น files
หรือ
changes
)
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-29 UTC
[null,null,["อัปเดตล่าสุด 2025-08-29 UTC"],[],[],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`)."]]