List labels on a file

Stay organized with collections Save and categorize content based on your preferences.

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. To list the file labels, use the files.listLabels method.

You also need to specify:

  • The fileId of the file for which you want the list of labels.

This example uses the label fileId to retrieve the correct labels.

Java

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

Python

label_list_response = drive_service.files().listLabels(fileId="FILE_ID");

Node.js

/**
* Lists all the labels on a Drive file
* @return{obj} a list of Labels
**/
async function modifyLabelTextField() {
  // 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;
  }
}