ยกเลิกการตั้งค่าช่องป้ายกำกับในไฟล์
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
หน้านี้จะอธิบายวิธีเลิกตั้งค่าป้ายกำกับ
Field
ในไฟล์ Google ไดรฟ์ไฟล์เดียว
หากต้องการนำข้อมูลเมตาออกจากไฟล์โดยยกเลิกการตั้งค่าป้ายกำกับไฟล์ ให้ใช้วิธี files.modifyLabels
เนื้อหาของคำขอ
มีอินสแตนซ์ของ
ModifyLabelsRequest
เพื่อแก้ไขชุดป้ายกำกับในไฟล์ คำขออาจมีการแก้ไขหลายรายการ
ซึ่งจะใช้พร้อมกัน กล่าวคือ หากการแก้ไขใดไม่ถูกต้อง การอัปเดตทั้งหมดจะไม่สำเร็จและระบบจะไม่ใช้การเปลี่ยนแปลงใดๆ (ซึ่งอาจขึ้นอยู่กับรายการอื่น)
ModifyLabelsRequest
มีอินสแตนซ์ของ
LabelModification
ซึ่งเป็นการแก้ไขป้ายกำกับในไฟล์ นอกจากนี้ยังอาจมีอินสแตนซ์
ของ
FieldModification
ซึ่งเป็นการแก้ไขฟิลด์ของป้ายกำกับ หากต้องการยกเลิกการตั้งค่าสำหรับช่อง ให้ตั้งค่า FieldModification.unsetValues
เป็น True
หากทำสำเร็จ เนื้อหา
การตอบกลับจะมีป้ายกำกับที่คำขอเพิ่มหรืออัปเดต ซึ่งอยู่ในออบเจ็กต์ modifiedLabels
ประเภท Label
ตัวอย่าง
ตัวอย่างโค้ดต่อไปนี้แสดงวิธีใช้ fieldId
และ labelId
เพื่อยกเลิกการตั้งค่า
ค่าฟิลด์ใน fileId
ที่เชื่อมโยง เช่น หากป้ายกำกับมีทั้งฟิลด์ข้อความและฟิลด์ผู้ใช้ การยกเลิกการตั้งค่าฟิลด์ข้อความจะนำฟิลด์ข้อความออกจากป้ายกำกับ แต่จะไม่เปลี่ยนแปลงฟิลด์ผู้ใช้ ในขณะที่การนำป้ายกำกับออกจะลบทั้งข้อความและช่องผู้ใช้ที่เชื่อมโยงกับป้ายกำกับ ดูข้อมูลเพิ่มเติมได้ที่นำป้ายกำกับออกจากไฟล์
Java
LabelFieldModification fieldModification =
new LabelFieldModification().setFieldId("FIELD_ID").setUnsetValues(true);
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','unsetValues':True}
label_modification = {'labelId':'LABEL_ID', 'fieldModifications':[field_modification]}
modified_labels = drive_service.files().modifyLabels(fileId="FILE_ID", body = {'labelModifications' : [label_modification]}).execute();
Node.js
/**
* Unset a label with a field on a Drive file
* @return{obj} updated label data
**/
async function unsetLabelField() {
// 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',
'unsetValues': True,
};
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
- LABEL_ID:
labelId
ของป้ายกำกับที่จะแก้ไข
- FILE_ID:
fileId
ของไฟล์ที่มีการแก้ไขป้ายกำกับ
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-29 UTC
[null,null,["อัปเดตล่าสุด 2025-08-29 UTC"],[],[],null,["# Unset a label field on a file\n\nThis page describes how to unset a label\n[`Field`](/workspace/drive/labels/reference/rest/v2/labels#field) on a single\nGoogle Drive file.\n\nTo remove metadata from a file by unsetting 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. To unset the values for the field,\nset `FieldModification.unsetValues` to `True`.\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` and `labelId` to unset\nthe field values on the associated `fileId`. For example, if a label contains\nboth text and user fields, unsetting the text field removes it from the label\nbut leaves the user field untouched. Whereas removing a label deletes *both* the\ntext and user fields associated with the label. For more information, see\n[Remove a label from a file](/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\").setUnsetValues(true);\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','unsetValues':True}\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 * Unset a label with a field on a Drive file\n * @return{obj} updated label data\n **/\n async function unsetLabelField() {\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 'unsetValues': True,\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\"\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."]]