องค์กรของคุณมีป้ายกำกับได้หลายป้าย โดยป้ายกำกับจะมีฟิลด์กี่ฟิลด์ก็ได้ หน้านี้จะอธิบายวิธีแสดงป้ายกำกับทั้งหมดในไฟล์ Google ไดรฟ์ ไฟล์เดียว
หากต้องการแสดงรายการป้ายกำกับไฟล์ ให้ใช้เมธอด
files.listLabels เนื้อหาคำขอต้องว่างเปล่า นอกจากนี้ เมธอดนี้ยังใช้พารามิเตอร์การค้นหาที่ไม่บังคับ
maxResults เพื่อกำหนดจำนวนป้ายกำกับสูงสุดที่จะแสดงต่อหน้า หากไม่ได้ตั้งค่าไว้ ระบบจะแสดงผลลัพธ์ 100 รายการ
หากทำสำเร็จ response
body จะมี
รายการป้ายกำกับที่ใช้กับไฟล์ โดยจะอยู่ในออบเจ็กต์ items ประเภท
Label
ตัวอย่าง
ตัวอย่างโค้ดต่อไปนี้แสดงวิธีใช้ fileId ของป้ายกำกับเพื่อดึงป้ายกำกับที่ถูกต้อง
Java
List<Label> labelList =
labelsDriveClient.files().listLabels("FILE_ID").execute().getItems();
Python
label_list_response = drive_service.files().listLabels(fileId="FILE_ID").execute();
Node.js
/**
* Lists all the labels on a Drive file
* @return{obj} a list of Labels
**/
async function listLabels() {
// 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 labelListResponse = await service.files.listLabels({
fileId: 'FILE_ID',
});
return labelListResponse;
} catch (err) {
// TODO (developer) - Handle error
throw err;
}
}
แทนที่ FILE_ID ด้วย fileId ของไฟล์ที่คุณต้องการดูรายการป้ายกำกับ