Method: files.modifyLabels
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.
Sửa đổi bộ nhãn được áp dụng cho một tệp. Để biết thêm thông tin, hãy xem bài viết Đặt trường nhãn cho tệp.
Trả về danh sách các nhãn đã được thêm hoặc sửa đổi.
Yêu cầu HTTP
POST https://www.googleapis.com/drive/v3/files/{fileId}/modifyLabels
URL sử dụng cú pháp Chuyển mã gRPC.
Tham số đường dẫn
Thông số |
fileId |
string
Mã nhận dạng của tệp chứa nhãn.
|
Nội dung yêu cầu
Nội dung yêu cầu chứa một bản sao của ModifyLabelsRequest
.
Nội dung phản hồi
Phản hồi yêu cầu files.modifyLabels
. Chỉ chứa những nhãn được yêu cầu thêm hoặc cập nhật.
Nếu thành công, phần nội dung phản hồi sẽ chứa dữ liệu có cấu trúc sau:
Biểu diễn dưới dạng JSON |
{
"modifiedLabels": [
{
object (Label )
}
],
"kind": string
} |
Trường |
modifiedLabels[] |
object (Label )
Danh sách nhãn được thêm hoặc cập nhật theo yêu cầu.
|
kind |
string
Trạng thái này luôn là "drive#modifyLabelsResponse" .
|
Phạm vi uỷ quyền
Yêu cầu một trong các phạm vi OAuth sau:
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/drive.metadata
Một số phạm vi bị hạn chế và yêu cầu bạn phải đánh giá bảo mật để ứng dụng của bạn có thể sử dụng các phạm vi đó. Để biết thêm thông tin, hãy xem Hướng dẫn uỷ quyền.
ModifyLabelsRequest
Yêu cầu sửa đổi bộ nhãn trên một tệp. Yêu cầu này có thể chứa nhiều nội dung sửa đổi, tất cả đều sẽ thành công hoặc không thành công một cách nhất quán.
Biểu diễn dưới dạng JSON |
{
"labelModifications": [
{
object (LabelModification )
}
],
"kind": string
} |
Trường |
labelModifications[] |
object (LabelModification )
Danh sách các nội dung sửa đổi cần áp dụng cho nhãn trên tệp.
|
kind |
string
Trạng thái này luôn là "drive#modifyLabelsRequest" .
|
LabelModification
Một nhãn trên tệp bị sửa đổi. Bạn có thể dùng LabelModification
để áp dụng nhãn cho tệp, cập nhật nhãn hiện có trên tệp hoặc xoá nhãn khỏi tệp.
Biểu diễn dưới dạng JSON |
{
"fieldModifications": [
{
object (FieldModification )
}
],
"labelId": string,
"removeLabel": boolean,
"kind": string
} |
Trường |
fieldModifications[] |
object (FieldModification )
Danh sách các nội dung sửa đổi đối với các trường của nhãn này.
|
labelId |
string
Mã của nhãn cần sửa đổi.
|
removeLabel |
boolean
Nếu là true, nhãn sẽ bị xoá khỏi tệp.
|
kind |
string
Trạng thái này luôn là "drive#labelModification" .
|
FieldModification
Một thay đổi đối với trường của nhãn.
Biểu diễn dưới dạng JSON |
{
"setDateValues": [
string
],
"setTextValues": [
string
],
"setSelectionValues": [
string
],
"setIntegerValues": [
string
],
"setUserValues": [
string
],
"fieldId": string,
"kind": string,
"unsetValues": boolean
} |
Trường |
setDateValues[] |
string
Thay thế giá trị của trường date bằng các giá trị mới này. Chuỗi phải ở định dạng ngày đầy đủ theo RFC 3339: YYYY-MM-DD.
|
setTextValues[] |
string
Đặt giá trị của trường text .
|
setSelectionValues[] |
string
Thay thế trường selection bằng các giá trị mới này.
|
setIntegerValues[] |
string (int64 format)
Thay thế giá trị của trường integer bằng các giá trị mới này.
|
setUserValues[] |
string
Thay thế trường user bằng các giá trị mới này. Giá trị phải là địa chỉ email hợp lệ.
|
fieldId |
string
Mã của trường cần sửa đổi.
|
kind |
string
Trạng thái này luôn là "drive#labelFieldModification" .
|
unsetValues |
boolean
Huỷ đặt các giá trị cho trường này.
|
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-27 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-27 UTC."],[],[],null,["# Method: files.modifyLabels\n\n- [HTTP request](#body.HTTP_TEMPLATE)\n- [Path parameters](#body.PATH_PARAMETERS)\n- [Request body](#body.request_body)\n- [Response body](#body.response_body)\n - [JSON representation](#body.ModifyLabelsResponse.SCHEMA_REPRESENTATION)\n- [Authorization scopes](#body.aspect)\n- [ModifyLabelsRequest](#ModifyLabelsRequest)\n - [JSON representation](#ModifyLabelsRequest.SCHEMA_REPRESENTATION)\n- [LabelModification](#LabelModification)\n - [JSON representation](#LabelModification.SCHEMA_REPRESENTATION)\n- [FieldModification](#FieldModification)\n - [JSON representation](#FieldModification.SCHEMA_REPRESENTATION)\n- [Try it!](#try-it)\n\nModifies the set of labels applied to a file. Returns a list of the labels that were added or modified.\n\n### HTTP request\n\n`POST https://www.googleapis.com/drive/v3/files/{fileId}/modifyLabels`\n\nThe URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.\n\n### Path parameters\n\n| Parameters ||\n|----------|---------------------------------------------------------|\n| `fileId` | `string` The ID of the file to which the labels belong. |\n\n### Request body\n\nThe request body contains an instance of [ModifyLabelsRequest](/workspace/drive/api/reference/rest/v3/files/modifyLabels#ModifyLabelsRequest).\n\n### Response body\n\nResponse to a files.modifyLabels request. This contains only those labels which were added or updated by the request.\n\nIf successful, the response body contains data with the following structure:\n\n| JSON representation |\n|-------------------------------------------------------------------------------------------------------------|\n| ``` { \"modifiedLabels\": [ { object (/workspace/drive/api/reference/rest/v3/Label) } ], \"kind\": string } ``` |\n\n| Fields ||\n|--------------------|-----------------------------------------------------------------------------------------------------------------------------------|\n| `modifiedLabels[]` | `object (`[Label](/workspace/drive/api/reference/rest/v3/Label)`)` The list of labels which were added or updated by the request. |\n| `kind` | `string` This is always drive#modifyLabelsResponse |\n\n### Authorization scopes\n\nRequires one of the following OAuth scopes:\n\n- `https://www.googleapis.com/auth/drive`\n- `\n https://www.googleapis.com/auth/drive.file`\n- `\n https://www.googleapis.com/auth/drive.metadata`\n\nSome scopes are restricted and require a security assessment for your app to use them. For more information, see the [Authorization guide](/workspace/guides/configure-oauth-consent).\n\nModifyLabelsRequest\n-------------------\n\nA request to modify the set of labels on a file. This request may contain many modifications that will either all succeed or all fail atomically.\n\n| JSON representation |\n|------------------------------------------------------------------------------------------------------------------------------------------------|\n| ``` { \"labelModifications\": [ { object (/workspace/drive/api/reference/rest/v3/files/modifyLabels#LabelModification) } ], \"kind\": string } ``` |\n\n| Fields ||\n|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `labelModifications[]` | `object (`[LabelModification](/workspace/drive/api/reference/rest/v3/files/modifyLabels#LabelModification)`)` The list of modifications to apply to the labels on the file. |\n| `kind` | `string` This is always drive#modifyLabelsRequest. |\n\nLabelModification\n-----------------\n\nA modification to a label on a file. A LabelModification can be used to apply a label to a file, update an existing label on a file, or remove a label from a file.\n\n| JSON representation |\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ``` { \"fieldModifications\": [ { object (/workspace/drive/api/reference/rest/v3/files/modifyLabels#FieldModification) } ], \"labelId\": string, \"removeLabel\": boolean, \"kind\": string } ``` |\n\n| Fields ||\n|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `fieldModifications[]` | `object (`[FieldModification](/workspace/drive/api/reference/rest/v3/files/modifyLabels#FieldModification)`)` The list of modifications to this label's fields. |\n| `labelId` | `string` The ID of the label to modify. |\n| `removeLabel` | `boolean` If true, the label will be removed from the file. |\n| `kind` | `string` This is always drive#labelModification. |\n\nFieldModification\n-----------------\n\nA modification to a label's field.\n\n| JSON representation |\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ``` { \"setDateValues\": [ string ], \"setTextValues\": [ string ], \"setSelectionValues\": [ string ], \"setIntegerValues\": [ string ], \"setUserValues\": [ string ], \"fieldId\": string, \"kind\": string, \"unsetValues\": boolean } ``` |\n\n| Fields ||\n|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|\n| `setDateValues[]` | `string` Replaces the value of a `date` field with these new values. The string must be in the RFC 3339 full-date format: YYYY-MM-DD. |\n| `setTextValues[]` | `string` Sets the value of a `text` field. |\n| `setSelectionValues[]` | `string` Replaces a `selection` field with these new values. |\n| `setIntegerValues[]` | `string (`[int64](https://developers.google.com/discovery/v1/type-format)` format)` Replaces the value of an `integer` field with these new values. |\n| `setUserValues[]` | `string` Replaces a `user` field with these new values. The values must be valid email addresses. |\n| `fieldId` | `string` The ID of the field to be modified. |\n| `kind` | `string` This is always drive#labelFieldModification. |\n| `unsetValues` | `boolean` Unsets the values for this field. |"]]