Google Drive API รองรับการค้นหาไฟล์และโฟลเดอร์ได้หลายวิธี
คุณสามารถใช้เมธอด files.list
เพื่อส่งคืน
ไฟล์และโฟลเดอร์ทั้งหมดหรือบางส่วนของผู้ใช้ไดรฟ์ files.list
นอกจากนี้ยังใช้เพื่อเรียกข้อมูล fileId
ที่จำเป็นสำหรับทรัพยากรบางรายการได้ด้วย
เมธอด (เช่น files.get
และ
files.update
)
ค้นหาไฟล์และโฟลเดอร์ทั้งหมดในไดรฟ์ของฉันของผู้ใช้ปัจจุบัน
ใช้เมธอด files.list
โดยไม่มีพารามิเตอร์ใดๆ เพื่อแสดงผลไฟล์ทั้งหมดและ
โฟลเดอร์
GET https://www.googleapis.com/drive/v3/files
ค้นหาไฟล์หรือโฟลเดอร์ที่ต้องการในไดรฟ์ของฉันของผู้ใช้ปัจจุบัน
หากต้องการค้นหาชุดไฟล์หรือโฟลเดอร์ที่ต้องการ ให้ใช้ช่องสตริง q
โดยใช้เมธอด files.list
เพื่อกรอง
ที่จะส่งคืนโดยการรวมข้อความค้นหา 1 คำขึ้นไป
สตริงการค้นหาประกอบด้วย 3 ส่วนต่อไปนี้
query_term operator values
สถานที่:
query_term
คือคำหรือฟิลด์ค้นหาสำหรับค้นหาoperator
ระบุเงื่อนไขของคำค้นหาvalues
คือค่าเฉพาะที่คุณต้องการใช้เพื่อกรองการค้นหา ผลลัพธ์
หากต้องการดูคําค้นหาและโอเปอเรเตอร์ที่คุณสามารถใช้กรองไฟล์และโฟลเดอร์ได้ ดูคำค้นหาและโอเปอเรเตอร์
ตัวอย่างเช่น สตริงคำค้นหาต่อไปนี้จะกรองการค้นหาให้แสดงเฉพาะผลลัพธ์ โดยการตั้งค่าประเภท MIME ดังนี้
q: mimeType = 'application/vnd.google-apps.folder'
โปรดดูข้อมูลเพิ่มเติมเกี่ยวกับประเภท MIME ที่หัวข้อ Google Workspace และ Google ไดรฟ์ ประเภท MIME ที่รองรับ
ตัวอย่างสตริงการค้นหา
ตารางต่อไปนี้แสดงตัวอย่างสตริงการค้นหาพื้นฐานบางรายการ โค้ดจริง จะแตกต่างกันไปตามไลบรารีของไคลเอ็นต์ที่คุณใช้ในการค้นหา
นอกจากนี้ คุณต้องไม่ใช้อักขระพิเศษในชื่อไฟล์เพื่อให้แน่ใจว่า
ทำงานได้อย่างถูกต้อง เช่น หากชื่อไฟล์มีทั้งเครื่องหมายอะพอสทรอฟี
('
) และอักขระแบ็กสแลช ("\"
) ให้ใช้เครื่องหมายแบ็กสแลชเพื่อหลีก: name
contains 'quinn\'s paper\\essay'
สิ่งที่คุณต้องการค้นหา | ตัวอย่าง |
---|---|
ไฟล์ชื่อ "สวัสดี" | name = 'hello' |
ไฟล์ที่มีชื่อที่มีคำว่า "สวัสดี" และ "ลาก่อน" | name contains 'hello' and name contains 'goodbye' |
ไฟล์ที่มีชื่อที่ไม่มีคำว่า "สวัสดี" | not name contains 'hello' |
ไฟล์ที่มีข้อความ "สำคัญ" และในถังขยะ | fullText contains 'important' and trashed = true |
ไฟล์ที่มีคำว่า "สวัสดี" | fullText contains 'hello' |
ไฟล์ที่ไม่มีคำว่า "สวัสดี" | not fullText contains 'hello' |
ไฟล์ที่มีวลี "สวัสดีโลก" ทุกประการ | fullText contains '"hello world"' |
ไฟล์ที่มีการค้นหาที่มีคำว่า "\" อักขระ (เช่น "\authors") | fullText contains '\\authors' |
ไฟล์ที่เป็นโฟลเดอร์ | mimeType = 'application/vnd.google-apps.folder' |
ไฟล์ที่ไม่ใช่โฟลเดอร์ | mimeType != 'application/vnd.google-apps.folder' |
ไฟล์ที่แก้ไขหลังจากวันที่ที่ระบุ (เขตเวลาเริ่มต้นคือ UTC) | modifiedTime > '2012-06-04T12:00:00' |
ไฟล์รูปภาพหรือวิดีโอที่แก้ไขหลังวันที่ที่ระบุ | modifiedTime > '2012-06-04T12:00:00' and (mimeType contains 'image/' or mimeType contains 'video/') |
ไฟล์ที่ติดดาว | starred = true |
ไฟล์ภายในคอลเล็กชัน (เช่น รหัสโฟลเดอร์ในคอลเล็กชัน parents ) |
'1234567' in parents |
ไฟล์ในโฟลเดอร์ข้อมูลแอปพลิเคชันในคอลเล็กชัน | 'appDataFolder' in parents |
ไฟล์ของผู้ใช้ "test@example.org" เป็นเจ้าของ | 'test@example.org' in owners |
ไฟล์ของผู้ใช้ "test@example.org" มีสิทธิ์เขียน | 'test@example.org' in writers |
ไฟล์ที่สมาชิกของกลุ่ม "group@example.org" มีสิทธิ์เขียน | 'group@example.org' in writers |
ไฟล์ที่แชร์กับผู้ใช้ที่ได้รับอนุญาตพร้อมคำว่า "สวัสดี" ในชื่อ | sharedWithMe and name contains 'hello' |
ไฟล์ที่มีพร็อพเพอร์ตี้ไฟล์ที่กำหนดเองซึ่งปรากฏแก่ทุกแอป | properties has { key='mass' and value='1.3kg' } |
ไฟล์ที่มีพร็อพเพอร์ตี้ไฟล์ที่กำหนดเองซึ่งเป็นแบบส่วนตัวของแอปที่ขอ | appProperties has { key='additionalID' and value='8e8aceg2af2ge72e78' } |
ไฟล์ที่ไม่ได้แชร์กับใครหรือโดเมนใดๆ (เฉพาะส่วนตัว หรือแชร์กับผู้ใช้หรือกลุ่มที่ระบุ) | visibility = 'limited' |
กรองผลการค้นหาด้วยไลบรารีของไคลเอ็นต์
ตัวอย่างโค้ดต่อไปนี้แสดงวิธีใช้ไลบรารีของไคลเอ็นต์เพื่อกรองการค้นหา
ผลลัพธ์ไปยังชื่อไฟล์และรหัสของไฟล์ JPEG ตัวอย่างนี้ใช้ mimeType
ข้อความค้นหาเพื่อจำกัดผลลัพธ์เฉพาะไฟล์ประเภท image/jpeg
และยังตั้งค่า
spaces
ไปยัง drive
เพื่อจำกัดขอบเขตการค้นหาเป็น ไดรฟ์ให้แคบลงอีก
พื้นที่ทำงาน เมื่อ nextPageToken
แสดงผล null
ไม่มีผลลัพธ์เพิ่มเติมแล้ว
Java
Python
Node.js
PHP
ค้นหาไฟล์ด้วยพร็อพเพอร์ตี้ไฟล์ที่กำหนดเอง
หากต้องการค้นหาไฟล์ที่มีพร็อพเพอร์ตี้ไฟล์ที่กำหนดเอง ให้ใช้แอตทริบิวต์ properties
หรือ
คำค้นหา appProperties
ที่มีคีย์และค่า ตัวอย่างเช่น หากต้องการ
ค้นหาพร็อพเพอร์ตี้ไฟล์ที่กำหนดเองซึ่งเป็นข้อมูลส่วนตัวของแอปที่ขอที่เรียกว่า
additionalID
ที่มีค่า 8e8aceg2af2ge72e78
:
appProperties has { key='additionalID' and value='8e8aceg2af2ge72e78' }
ดูข้อมูลเพิ่มเติมได้ที่เพิ่มไฟล์ที่กำหนดเอง พร็อพเพอร์ตี้
ค้นหาไฟล์ที่มีป้ายกำกับหรือค่าในช่องที่เฉพาะเจาะจง
หากต้องการค้นหาไฟล์ที่มีป้ายกำกับที่ต้องการ ให้ใช้คำค้นหา labels
ด้วยรหัสป้ายกำกับที่เฉพาะเจาะจง เช่น 'labels/LABEL_ID' in
labels
หากทำสำเร็จ เนื้อหาการตอบกลับจะมีอินสแตนซ์ของไฟล์ทั้งหมดที่ระบุส่วน
ใช้ป้ายกำกับแล้ว
หากต้องการค้นหาไฟล์ที่ไม่มีรหัสป้ายกำกับที่เจาะจง: Not
'labels/LABEL_ID' in labels
คุณยังค้นหาไฟล์ตามค่าในช่องที่เฉพาะเจาะจงได้อีกด้วย ตัวอย่างเช่น หากต้องการ
ค้นหาไฟล์ที่มีค่าข้อความ:
labels/LABEL_ID.text_field_id ='TEXT'
โปรดดูข้อมูลเพิ่มเติมที่หัวข้อค้นหาไฟล์ที่มีป้ายกำกับหรือช่องที่ต้องการ
ค้นหาคลังข้อมูล
การค้นหาที่เรียก files.list
ใช้องค์ประกอบ
corpora
จาก user
โดยค่าเริ่มต้น วิธีการค้นหา
กลุ่มเนื้อหาอื่นๆ เช่น ไฟล์ที่แชร์กับ domain
ให้ตั้งค่า corpora
พารามิเตอร์
อาจมีการค้นหาคลังข้อมูลหลายรายการด้วยคำค้นหาเดียว แม้ว่าผลลัพธ์จะไม่สมบูรณ์
อาจส่งคืนหากคลังข้อมูลแบบรวมมีขนาดใหญ่เกินไป หาก incompleteSearch
คือ
true
ในเนื้อหาการตอบกลับ ระบบจึงไม่ส่งคืนเอกสารทั้งหมด หากสิ่งนี้
คุณควรจำกัดการค้นหาให้แคบลงโดยเลือกกลุ่มเนื้อหาอื่น เช่น
user
หรือ drive
หัวข้อที่เกี่ยวข้อง
- ค้นหาไดรฟ์ที่แชร์
- คำค้นหาและโอเปอเรเตอร์
- ประเภท MIME ที่รองรับ Google Workspace และ Google ไดรฟ์
- บทบาทและสิทธิ์
- ค้นหาไฟล์ที่มีป้ายกำกับหรือค่าในช่องที่เฉพาะเจาะจง