किसी फ़ाइल पर लेबल फ़ील्ड सेट करना
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
इस पेज पर, Google Drive की किसी फ़ाइल पर लेबल Field
सेट करने का तरीका बताया गया है.
किसी फ़ाइल में मेटाडेटा जोड़ने के लिए, फ़ाइल का लेबल सेट करें. इसके लिए, files.modifyLabels
तरीके का इस्तेमाल करें. अनुरोध के मुख्य हिस्से में, किसी फ़ाइल पर लेबल के सेट में बदलाव करने के लिए ModifyLabelsRequest
का एक इंस्टेंस शामिल होता है. अनुरोध में कई बदलाव शामिल हो सकते हैं, जिन्हें एक साथ लागू किया जाता है. इसका मतलब है कि अगर कोई बदलाव मान्य नहीं है, तो पूरा अपडेट लागू नहीं होगा. साथ ही, (संभावित रूप से निर्भर) कोई भी बदलाव लागू नहीं होगा.
ModifyLabelsRequest
में LabelModification
का एक इंस्टेंस शामिल है. यह फ़ाइल के लेबल में किया गया बदलाव है. इसमें FieldModification
का कोई इंस्टेंस भी शामिल हो सकता है. यह लेबल के फ़ील्ड में किया गया बदलाव होता है.
अगर अनुरोध पूरा हो जाता है, तो जवाब के मुख्य हिस्से में, अनुरोध के ज़रिए जोड़े गए या अपडेट किए गए लेबल शामिल होते हैं. ये Label
टाइप के modifiedLabels
ऑब्जेक्ट में मौजूद होते हैं.
उदाहरण
यहां दिए गए कोड के उदाहरण में बताया गया है कि किसी फ़ाइल में मौजूद Field
के लिए वैल्यू सेट करने के लिए, टेक्स्ट फ़ील्ड के fieldId
का इस्तेमाल कैसे किया जाता है. जब किसी फ़ाइल पर पहली बार कोई लेबल Field
सेट किया जाता है, तो वह लेबल उस फ़ाइल पर लागू हो जाता है. इसके बाद, किसी एक फ़ील्ड से लेबल हटाया जा सकता है या लेबल से जुड़े सभी फ़ील्ड हटाए जा सकते हैं. ज़्यादा जानकारी के लिए, किसी फ़ाइल से लेबल फ़ील्ड को अनसेट करना और किसी फ़ाइल से लेबल हटाना लेख पढ़ें.
Java
LabelFieldModification fieldModification =
new LabelFieldModification().setFieldId("FIELD_ID").setSetTextValues(ImmutableList.of("VALUE"));
ModifyLabelsRequest modifyLabelsRequest =
new ModifyLabelsRequest()
.setLabelModifications(
ImmutableList.of(
new LabelModification()
.setLabelId("LABEL_ID")
.setFieldModifications(ImmutableList.of(fieldModification))));
ModifyLabelsResponse modifyLabelsResponse = driveService.files().modifyLabels("FILE_ID", modifyLabelsRequest).execute();
Python
field_modification = {'fieldId':'FIELD_ID','setTextValues':['VALUE']}
label_modification = {'labelId':'LABEL_ID', 'fieldModifications':[field_modification]}
modified_labels = drive_service.files().modifyLabels(fileId="FILE_ID", body = {'labelModifications' : [label_modification]}).execute()
Node.js
/**
* Set a label with a text field on a Drive file
* @return{obj} updated label data
**/
async function setLabelTextField() {
// 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});
const fieldModification = {
'fieldId': 'FIELD_ID',
'setTextValues': ['VALUE'],
};
const labelModification = {
'labelId': 'LABEL_ID',
'fieldModifications': [fieldModification],
};
const labelModificationRequest = {
'labelModifications': [labelModification],
};
try {
const updateResponse = await service.files.modifyLabels({
fileId: 'FILE_ID',
resource: labelModificationRequest,
});
return updateResponse;
} catch (err) {
// TODO (developer) - Handle error
throw err;
}
}
इनकी जगह ये डालें:
- FIELD_ID: बदलाव किए जाने वाले फ़ील्ड का
fieldId
. fieldId
का पता लगाने के लिए, Google Drive Labels API का इस्तेमाल करके लेबल वापस पाएं.
- VALUE: इस फ़ील्ड के लिए नया
value
.
- LABEL_ID: बदलाव करने के लिए लेबल का
labelId
.
- FILE_ID: यह उस फ़ाइल का
fileId
है जिसके लेबल में बदलाव किया गया है.
नोट
- बिना फ़ील्ड वाला लेबल सेट करने के लिए,
labelModifications
लागू करें. इसमें fieldModifications
मौजूद नहीं होना चाहिए.
- चुने जाने वाले फ़ील्ड के विकल्पों के लिए वैल्यू सेट करने के लिए, वैल्यू के
Choice
आईडी का इस्तेमाल करें. यह आईडी, Drive Labels API में लेबल स्कीमा फ़ेच करके पाया जा सकता है.
- सिर्फ़ ऐसे
Field
के लिए एक से ज़्यादा वैल्यू सेट की जा सकती हैं जिनमें वैल्यू की सूचियां इस्तेमाल की जा सकती हैं. इसके अलावा, आपको 400: Bad Request
गड़बड़ी का जवाब मिलेगा.
- चुने गए
Field
के लिए, वैल्यू का सही टाइप सेट करें. जैसे, पूर्णांक, टेक्स्ट, उपयोगकर्ता वगैरह. ऐसा न करने पर, आपको 400: Bad Request
गड़बड़ी का रिस्पॉन्स मिलेगा.
Drive Labels API का इस्तेमाल करके, फ़ील्ड के डेटा टाइप को वापस पाया जा सकता है.
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-08-29 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2025-08-29 (UTC) को अपडेट किया गया."],[],[],null,["# Set a label field on a file\n\nThis page describes how to set a label\n[`Field`](/workspace/drive/labels/reference/rest/v2/labels#field) on a single\nGoogle Drive file.\n\nTo add metadata to a file by setting a file label, use the\n[`files.modifyLabels`](/workspace/drive/api/v2/reference/files/modifyLabels) method. The\n[request body](/workspace/drive/api/reference/rest/v2/files/modifyLabels#request-body)\ncontains an instance of\n[`ModifyLabelsRequest`](/workspace/drive/api/reference/rest/v2/files/modifyLabels#modifylabelsrequest)\nto modify the set of labels on a file. The request might contain several\nmodifications that are applied atomically. That is, if any modifications aren't\nvalid, then the entire update is unsuccessful and none of the (potentially\ndependent) changes are applied.\n\nThe `ModifyLabelsRequest` contains an instance of\n[`LabelModification`](/workspace/drive/api/reference/rest/v2/files/modifyLabels#labelmodification)\nwhich is a modification to a label on a file. It might also contain an instance\nof\n[`FieldModification`](/workspace/drive/api/reference/rest/v2/files/modifyLabels#fieldmodification)\nwhich is a modification to a label's field.\n\nIf successful, the [response\nbody](/workspace/drive/api/reference/rest/v2/files/modifyLabels#response-body) contains\nthe labels added or updated by the request. These exist within a\n`modifiedLabels` object of type [`Label`](/workspace/drive/api/reference/rest/v2/Label).\n\nExample\n-------\n\nThe following code sample shows how to use the `fieldId` of a text field to set\na value for this [`Field`](/workspace/drive/labels/reference/rest/v2/labels#field) on a\nfile. When a label `Field` is initially set on a file, it applies the label to\nthe file. You can then unset a single field or remove all fields associated with\nthe label. For more information, see [Unset a label field on a\nfile](/workspace/drive/api/guides/unset-label) and [Remove a label from a\nfile](/workspace/drive/api/guides/remove-label). \n\n### Java\n\n LabelFieldModification fieldModification =\n new LabelFieldModification().setFieldId(\"\u003cvar translate=\"no\"\u003eFIELD_ID\u003c/var\u003e\").setSetTextValues(ImmutableList.of(\"\u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e\"));\n\n ModifyLabelsRequest modifyLabelsRequest =\n new ModifyLabelsRequest()\n .setLabelModifications(\n ImmutableList.of(\n new LabelModification()\n .setLabelId(\"\u003cvar translate=\"no\"\u003eLABEL_ID\u003c/var\u003e\")\n .setFieldModifications(ImmutableList.of(fieldModification))));\n\n ModifyLabelsResponse modifyLabelsResponse = driveService.files().modifyLabels(\"\u003cvar translate=\"no\"\u003eFILE_ID\u003c/var\u003e\", modifyLabelsRequest).execute();\n\n### Python\n\n field_modification = {'fieldId':'\u003cvar translate=\"no\"\u003eFIELD_ID\u003c/var\u003e','setTextValues':['\u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e']}\n label_modification = {'labelId':'\u003cvar translate=\"no\"\u003eLABEL_ID\u003c/var\u003e', 'fieldModifications':[field_modification]}\n\n modified_labels = drive_service.files().modifyLabels(fileId=\"\u003cvar translate=\"no\"\u003eFILE_ID\u003c/var\u003e\", body = {'labelModifications' : [label_modification]}).execute()\n\n### Node.js\n\n /**\n * Set a label with a text field on a Drive file\n * @return{obj} updated label data\n **/\n async function setLabelTextField() {\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 const fieldModification = {\n 'fieldId': '\u003cvar translate=\"no\"\u003eFIELD_ID\u003c/var\u003e',\n 'setTextValues': ['\u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e'],\n };\n const labelModification = {\n 'labelId': '\u003cvar translate=\"no\"\u003eLABEL_ID\u003c/var\u003e',\n 'fieldModifications': [fieldModification],\n };\n const labelModificationRequest = {\n 'labelModifications': [labelModification],\n };\n try {\n const updateResponse = await service.files.modifyLabels({\n fileId: '\u003cvar translate=\"no\"\u003eFILE_ID\u003c/var\u003e',\n resource: labelModificationRequest,\n });\n return updateResponse;\n } catch (err) {\n // TODO (developer) - Handle error\n throw err;\n }\n }\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eFIELD_ID\u003c/var\u003e: The `fieldId` of the field to modify. To locate the `fieldId`, retrieve the label using the [Google Drive Labels API](/workspace/drive/labels/guides/search-label).\n- \u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e: The new `value` for this field.\n- \u003cvar translate=\"no\"\u003eLABEL_ID\u003c/var\u003e: The `labelId` of the label to modify.\n- \u003cvar translate=\"no\"\u003eFILE_ID\u003c/var\u003e: The `fileId` of the file for which the labels are modified.\n\nNotes\n-----\n\n- To set a label with no fields, apply `labelModifications` with no `fieldModifications` present.\n- To set values for selection field options, use the [`Choice`](/workspace/drive/labels/reference/rest/v2/labels#choice) id of the value that you can get by fetching the label schema in the [Drive Labels API](/workspace/drive/labels/guides/overview).\n- Only a `Field` that supports lists of values can have multiple values set, otherwise you'll receive a `400: Bad Request` error response.\n- Set the proper value type for the selected `Field` (such as integer, text, user, etc.), otherwise you'll receive a `400: Bad Request` error response. You can retrieve the field data type using the [Drive Labels API](/workspace/drive/labels/reference/rest/v2/labels#field)."]]