Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Trang này mô tả cách huỷ đặt nhãn Field trên một tệp duy nhất trong Google Drive.
Để xoá siêu dữ liệu khỏi một tệp bằng cách huỷ đặt nhãn tệp, hãy dùng phương thức files.modifyLabels. Nội dung yêu cầu chứa một phiên bản của ModifyLabelsRequest để sửa đổi bộ nhãn trên một tệp. Yêu cầu có thể chứa một số nội dung sửa đổi được áp dụng một cách riêng lẻ. Tức là nếu có bất kỳ nội dung sửa đổi nào không hợp lệ, thì toàn bộ quá trình cập nhật sẽ không thành công và không có thay đổi nào (có thể phụ thuộc) được áp dụng.
ModifyLabelsRequest chứa một thực thể của LabelModification. Đây là một nội dung sửa đổi đối với nhãn trên một tệp. Nội dung này cũng có thể chứa một thực thể của FieldModification. Đây là một điểm sửa đổi đối với trường của nhãn. Để huỷ đặt giá trị cho trường, hãy đặt FieldModification.unsetValues thành True.
Nếu thành công, nội dung phản hồi sẽ chứa các nhãn được thêm hoặc cập nhật theo yêu cầu. Các biến này nằm trong một đối tượng modifiedLabels thuộc loại Label.
Ví dụ:
Mã mẫu sau đây cho biết cách sử dụng fieldId và labelId để huỷ đặt các giá trị trường trên fileId được liên kết. Ví dụ: nếu một nhãn chứa cả trường văn bản và trường người dùng, thì việc huỷ đặt trường văn bản sẽ xoá trường đó khỏi nhãn nhưng không ảnh hưởng đến trường người dùng. Trong khi đó, việc xoá nhãn sẽ xoá cả văn bản và các trường người dùng liên kết với nhãn. Để biết thêm thông tin, hãy xem bài viết Xoá nhãn khỏi tệp.
/*** Unset a label with a field on a Drive file* @return{obj} updated label data**/asyncfunctionunsetLabelField(){// 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});constfieldModification={'fieldId':'FIELD_ID','unsetValues':True,};constlabelModification={'labelId':'LABEL_ID','fieldModifications':[fieldModification],};constlabelModificationRequest={'labelModifications':[labelModification],};try{constupdateResponse=awaitservice.files.modifyLabels({fileId:'FILE_ID',resource:labelModificationRequest,});returnupdateResponse;}catch(err){// TODO (developer) - Handle errorthrowerr;}}
Thay thế nội dung sau:
FIELD_ID: fieldId của trường cần sửa đổi. Để xác định vị trí fieldId, hãy truy xuất nhãn bằng Google Drive Labels API.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 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."]]