Method: files.modifyLabels
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
修改应用于文件的标签集。返回已添加或修改的标签的列表。
HTTP 请求
POST https://www.googleapis.com/drive/v2/files/{fileId}/modifyLabels
网址采用 gRPC 转码语法。
路径参数
参数 |
fileId |
string
标签所属文件的 ID。
|
响应正文
对 files.modifyLabels 请求的响应。此字段仅包含通过请求添加或更新的标签。
如果成功,响应正文将包含结构如下的数据:
JSON 表示法 |
{
"modifiedLabels": [
{
object (Label )
}
],
"kind": string
} |
字段 |
modifiedLabels[] |
object (Label )
相应请求添加或更新的标签的列表。
|
kind |
string
始终为 drive#modifyLabelsResponse
|
授权范围
需要以下 OAuth 范围之一:
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/drive.metadata
某些范围受到限制,您的应用需要通过安全评估才能使用这些范围。如需了解详情,请参阅授权指南。
ModifyLabelsRequest
修改文件上的一组标签的请求。此请求可能包含许多修改,这些修改要么全部成功,要么全部失败(以原子方式)。
JSON 表示法 |
{
"labelModifications": [
{
object (LabelModification )
}
],
"kind": string
} |
字段 |
labelModifications[] |
object (LabelModification )
要应用于文件标签的修改列表。
|
kind |
string
始终为 drive#modifyLabelsRequest 。
|
LabelModification
对文件标签的修改。LabelModification 可用于向文件应用标签、更新文件上的现有标签或从文件中移除标签。
JSON 表示法 |
{
"fieldModifications": [
{
object (FieldModification )
}
],
"labelId": string,
"removeLabel": boolean,
"kind": string
} |
字段 |
fieldModifications[] |
object (FieldModification )
相应标签的字段修改列表。
|
labelId |
string
要修改的标签的 ID。
|
removeLabel |
boolean
如果为 true,系统会将相应标签从文件中移除。
|
kind |
string
始终为 drive#labelModification 。
|
FieldModification
JSON 表示法 |
{
"setDateValues": [
string
],
"setTextValues": [
string
],
"setSelectionValues": [
string
],
"setIntegerValues": [
string
],
"setUserValues": [
string
],
"fieldId": string,
"kind": string,
"unsetValues": boolean
} |
字段 |
setDateValues[] |
string
将 date 字段的值替换为这些新值。字符串必须采用 RFC 3339 完整日期格式:YYYY-MM-DD。
|
setTextValues[] |
string
设置 text 字段的值。
|
setSelectionValues[] |
string
将 selection 字段替换为这些新值。
|
setIntegerValues[] |
string (int64 format)
将 integer 字段的值替换为这些新值。
|
setUserValues[] |
string
将 user 字段替换为这些新值。这些值必须是有效的电子邮件地址。
|
fieldId |
string
要修改的字段的 ID。
|
kind |
string
始终为 drive#labelFieldModification 。
|
unsetValues |
boolean
取消设置相应字段的值。
|
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[],[],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/v2/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/v2/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/v2/Label) } ], \"kind\": string } ``` |\n\n| Fields ||\n|--------------------|-----------------------------------------------------------------------------------------------------------------------------------|\n| `modifiedLabels[]` | `object (`[Label](/workspace/drive/api/reference/rest/v2/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/v2/files/modifyLabels#LabelModification) } ], \"kind\": string } ``` |\n\n| Fields ||\n|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `labelModifications[]` | `object (`[LabelModification](/workspace/drive/api/reference/rest/v2/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/v2/files/modifyLabels#FieldModification) } ], \"labelId\": string, \"removeLabel\": boolean, \"kind\": string } ``` |\n\n| Fields ||\n|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `fieldModifications[]` | `object (`[FieldModification](/workspace/drive/api/reference/rest/v2/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. |"]]