แสดงผลป้ายกำกับจากทรัพยากรไฟล์

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

Notes