หน้านี้จะอธิบายวิธีกู้คืนป้ายกำกับที่เฉพาะเจาะจงจากทรัพยากรไฟล์ใน Google ไดรฟ์
หากต้องการระบุป้ายกำกับที่ต้องการดึงข้อมูล ให้ใช้เมธอด
files.get
หรือเมธอดใดก็ได้ที่
แสดงผลทรัพยากรไฟล์ เนื้อหาของคำขอต้องว่างเปล่า
หากทำสำเร็จ เนื้อหา
การตอบกลับจะมีอินสแตนซ์
ของ File
ตัวอย่าง
ตัวอย่างโค้ดต่อไปนี้แสดงวิธีใช้ fileId
ร่วมกับ labelId
เพื่อ
แสดงชุดป้ายกำกับที่เฉพาะเจาะจง ออบเจ็กต์
includeLabels
คือรายการรหัสที่คั่นด้วยคอมมา labelInfo
ออบเจ็กต์ในพารามิเตอร์ fields
มีป้ายกำกับที่ตั้งค่าไว้ในไฟล์และขอภายใน includeLabels
Java
File file = driveService.files().get("FILE_ID").setIncludeLabels("LABEL_ID,LABEL_ID").setFields("labelInfo").execute();
Python
file = drive_service.files().get(fileId="FILE_ID", includeLabels="LABEL_ID,LABEL_ID", fields="labelInfo").execute();
Node.js
/**
* Get a Drive file with specific labels
* @return{obj} file with labelInfo
**/
async function getFileWithSpecificLabels() {
// Get credentials and build service
// TODO (developer) - Use appropriate auth mechanism for your app
const {GoogleAuth} = require('google-auth-library');
const {google} = require('googleapis');
const auth = new GoogleAuth({scopes: 'https://www.googleapis.com/auth/drive'});
const service = google.drive({version: 'v3', auth});
try {
const file = await service.files.get({
fileId: 'FILE_ID',
includeLabels: 'LABEL_ID,LABEL_ID',
fields:'labelInfo',
});
return file;
} catch (err) {
// TODO (developer) - Handle error
throw err;
}
}
แทนที่ค่าต่อไปนี้
- FILE_ID:
fileId
ของไฟล์ที่มีป้ายกำกับ - LABEL_ID:
labelId
ของป้ายกำกับที่จะแสดง หากต้องการค้นหา ป้ายกำกับในไฟล์ ให้ใช้วิธีfiles.listLabels
หมายเหตุ
- เมธอดที่แสดงผลทรัพยากร
ไฟล์รองรับฟิลด์และพารามิเตอร์การค้นหา
includeLabels
เช่นfiles.copy
files.list
และfiles.update