Stay organized with collections
Save and categorize content based on your preferences.
This page describes how to return specific labels from a Google Drive file
resource.
To specify which labels that you want to retrieve, use the
files.get method or any method that
returns a file resource. The request
body must be empty.
The following code sample shows how to use the fileId, plus the labelId, to
return the set of specific labels. The
includeLabels
object is a comma-separated list of IDs. The labelInfoobject in the fields
parameter contains labels set on the file and requested within includeLabels.
/*** Get a Drive file with specific labels* @return{obj} file with labelInfo**/asyncfunctiongetFileWithSpecificLabels(){// Get credentials and build service// TODO (developer) - Use appropriate auth mechanism for your appconst{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{constfile=awaitservice.files.get({fileId:'FILE_ID',includeLabels:'LABEL_ID,LABEL_ID',fields:'labelInfo',});returnfile;}catch(err){// TODO (developer) - Handle errorthrowerr;}}
Replace the following:
FILE_ID: The fileId of the file containing the labels.
LABEL_ID: The labelId of a label to return. To locate
the labels on a file, use the
files.listLabels method.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Return a label from a file resource\n\nThis page describes how to return specific labels from a Google Drive file\nresource.\n\nTo specify which labels that you want to retrieve, use the\n[`files.get`](/workspace/drive/api/v2/reference/files/get) method or any method that\nreturns a [file resource](/workspace/drive/labels/reference/rest/v2/labels). The request\nbody must be empty.\n\nIf successful, the [response\nbody](/workspace/drive/api/reference/rest/v2/files/get#response-body) contains an instance\nof [`File`](/workspace/drive/api/reference/rest/v2/files#File).\n\nExample\n-------\n\nThe following code sample shows how to use the `fileId`, plus the `labelId`, to\nreturn the set of specific labels. The\n[`includeLabels`](/workspace/drive/api/reference/rest/v2/files/get#query-parameters)\nobject is a comma-separated list of IDs. The `labelInfo`object in the `fields`\nparameter contains labels set on the file and requested within `includeLabels`. \n\n### Java\n\n File file = driveService.files().get(\"\u003cvar translate=\"no\"\u003eFILE_ID\u003c/var\u003e\").setIncludeLabels(\"\u003cvar translate=\"no\"\u003eLABEL_ID\u003c/var\u003e,\u003cvar translate=\"no\"\u003eLABEL_ID\u003c/var\u003e\").setFields(\"labelInfo\").execute();\n\n### Python\n\n file = drive_service.files().get(fileId=\"\u003cvar translate=\"no\"\u003eFILE_ID\u003c/var\u003e\", includeLabels=\"\u003cvar translate=\"no\"\u003eLABEL_ID\u003c/var\u003e,\u003cvar translate=\"no\"\u003eLABEL_ID\u003c/var\u003e\", fields=\"labelInfo\").execute();\n\n### Node.js\n\n /**\n * Get a Drive file with specific labels\n * @return{obj} file with labelInfo\n **/\n async function getFileWithSpecificLabels() {\n // Get credentials and build service\n // TODO (developer) - Use appropriate auth mechanism for your app\n\n const {GoogleAuth} = require('google-auth-library');\n const {google} = require('googleapis');\n\n const auth = new GoogleAuth({scopes: 'https://www.googleapis.com/auth/drive'});\n const service = google.drive({version: 'v3', auth});\n try {\n const file = await service.files.get({\n fileId: '\u003cvar translate=\"no\"\u003eFILE_ID\u003c/var\u003e',\n includeLabels: '\u003cvar translate=\"no\"\u003eLABEL_ID\u003c/var\u003e,\u003cvar translate=\"no\"\u003eLABEL_ID\u003c/var\u003e',\n fields:'labelInfo',\n });\n return file;\n } catch (err) {\n // TODO (developer) - Handle error\n throw err;\n }\n }\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eFILE_ID\u003c/var\u003e: The `fileId` of the file containing the labels.\n- \u003cvar translate=\"no\"\u003eLABEL_ID\u003c/var\u003e: The `labelId` of a label to return. To locate the labels on a file, use the [`files.listLabels`](/workspace/drive/api/v2/reference/files/listLabels) method.\n\nNotes\n-----\n\n- Any method returning a [file\n resource](/workspace/drive/labels/reference/rest/v2/labels) supports the `includeLabels` field and query parameter. For example, [`files.copy`](/workspace/drive/api/reference/rest/v2/files/copy), [`files.list`](/workspace/drive/api/reference/rest/v2/files/list), and [`files.update`](/workspace/drive/api/reference/rest/v2/files/update)."]]