List labels on a file

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. The request body must be empty. The method also takes the optional query parameter maxResults to set the maximum number of labels to return per page. If not set, 100 results are returned.

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

Example

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().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
**/
asyncfunctionlistLabels(){
// Get credentials and build service
// TODO (developer) - Use appropriate auth mechanism for your app
const{GoogleAuth}=require('google-auth-library');
const{google}=require('googleapis');
constauth=newGoogleAuth({scopes:'https://www.googleapis.com/auth/drive'});
constservice=google.drive({version:'v3',auth});
try{
constlabelListResponse=awaitservice.files.listLabels({
fileId:'FILE_ID',
});
returnlabelListResponse;
}catch(err){
// TODO (developer) - Handle error
throwerr;
}
}

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

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月13日 UTC.