แสดงรายการป้ายกำกับในไฟล์
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
องค์กรของคุณมีป้ายกำกับได้หลายป้าย โดยป้ายกำกับจะมีฟิลด์กี่ฟิลด์ก็ได้
หน้านี้จะอธิบายวิธีแสดงป้ายกำกับทั้งหมดในไฟล์ 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
ของไฟล์ที่ต้องการดูรายการป้ายกำกับ
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-04 UTC
[null,null,["อัปเดตล่าสุด 2025-08-04 UTC"],[],[],null,["# List labels on a file\n\nYour organization can have multiple labels, with labels having any number of\nfields. This page describes how to list all labels on a single Google Drive\nfile.\n\nTo list the file labels, use the\n[`files.listLabels`](/workspace/drive/api/v2/reference/files/listLabels) method. The\nrequest body must be empty. The method also takes the optional query parameter\n`maxResults` to set the maximum number of labels to return per page. If not set,\n100 results are returned.\n\nIf successful, the [response\nbody](/workspace/drive/api/reference/rest/v2/files/listLabels#response-body) contains the\nlist of labels applied to a file. These exist within an `items` object of type\n[`Label`](/workspace/drive/api/reference/rest/v2/Label).\n\nExample\n-------\n\nThe following code sample shows how to use the label's `fileId` to retrieve the\ncorrect labels. \n\n### Java\n\n List\u003cLabel\u003e labelList =\n labelsDriveClient.files().listLabels(\"\u003cvar translate=\"no\"\u003eFILE_ID\u003c/var\u003e\").execute().getItems();\n\n### Python\n\n label_list_response = drive_service.files().listLabels(fileId=\"\u003cvar translate=\"no\"\u003eFILE_ID\u003c/var\u003e\").execute();\n\n### Node.js\n\n /**\n * Lists all the labels on a Drive file\n * @return{obj} a list of Labels\n **/\n async function listLabels() {\n // Get credentials and build service\n // TODO (developer) - Use appropriate auth mechanism for your app\n\n const {GoogleAuth} = require('google-auth-library');\n const {google} = require('googleapis');\n\n const auth = new GoogleAuth({scopes: 'https://www.googleapis.com/auth/drive'});\n const service = google.drive({version: 'v3', auth});\n try {\n const labelListResponse = await service.files.listLabels({\n fileId: '\u003cvar translate=\"no\"\u003eFILE_ID\u003c/var\u003e',\n });\n return labelListResponse;\n } catch (err) {\n // TODO (developer) - Handle error\n throw err;\n }\n }\n\nReplace \u003cvar translate=\"no\"\u003eFILE_ID\u003c/var\u003e with the `fileId` of the file for which you\nwant the list of labels."]]