Список меток в файле

Your organization can have multiple labels, with labels having any number of fields. This page describes how to list all labels on a single Google Drive file.

Для вывода списка меток файлов используйте метод files.listLabels . Тело запроса должно быть пустым. Метод также принимает необязательный параметр запроса maxResults , устанавливающий максимальное количество меток, возвращаемых на странице. Если он не задан, возвращается 100 результатов.

If successful, the response body contains the list of labels applied to a file. These exist within an items object of type Label .

Пример

The following code sample shows how to use the label's fileId to retrieve the correct labels.

Java

List<Label> labelList = labelsDriveClient.files()
    .listLabels("FILE_ID")
    .execute()
    .getLabels();

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;
  }
}

Replace FILE_ID with the fileId of the file for which you want the list of labels.