파일의 라벨 나열

조직은 여러 개의 라벨을 가질 수 있으며, 라벨의 수에는 제한이 없습니다. 이 페이지에서는 단일 Google Drive 파일에 모든 라벨을 나열하는 방법을 설명합니다.

파일 라벨을 나열하려면 files.listLabels 메서드를 사용합니다. 요청 본문은 비어 있어야 합니다. 또한 이 메서드는 선택적 쿼리 매개변수 maxResults를 사용하여 페이지당 반환할 최대 라벨 수를 설정합니다. 설정하지 않으면 결과 100개가 반환됩니다.

성공하면 응답 본문에 파일에 적용된 라벨 목록이 포함됩니다. 이는 Label 유형의 items 객체 내에 있습니다.

다음 코드 샘플은 라벨의 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로 바꿉니다.