แสดงรายการป้ายกำกับในไฟล์

องค์กรของคุณมีป้ายกำกับได้หลายรายการ โดยที่ป้ายกำกับจะมีช่องข้อมูลกี่ช่องก็ได้ หน้านี้จะอธิบายวิธีแสดงป้ายกำกับทั้งหมดในไฟล์ Google ไดรฟ์ไฟล์เดียว

หากต้องการแสดงป้ายกำกับไฟล์ ให้ใช้เมธอด files.listLabels เนื้อหาของคำขอต้องว่างเปล่า วิธีนี้ยังใช้พารามิเตอร์การค้นหาที่ไม่บังคับ maxResults เพื่อกำหนดจำนวนป้ายกำกับสูงสุดที่จะแสดงต่อ 1 หน้า หากไม่ได้ตั้งค่า ระบบจะแสดงผลลัพธ์ 100 รายการ

หากทำสำเร็จ เนื้อหาการตอบกลับ จะมีรายการป้ายกำกับที่ใช้กับไฟล์ รายการเหล่านี้อยู่ในออบเจ็กต์ 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 ของไฟล์ที่คุณต้องการรายการป้ายกำกับ