หน้านี้อธิบายวิธีแสดงป้ายกำกับที่เฉพาะเจาะจงจากทรัพยากรไฟล์ 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