停用、启用和删除标签
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页面介绍了如何执行以下涉及标签的任务:
停用标签
停用标签会导致系统基于当前已发布的修订版本创建一个新的已停用的已发布修订版本。如果存在草稿修订版本,系统会根据最新的草稿修订版本创建一个新的已停用的草稿修订版本。较旧的草稿修订版本会被删除。如需了解详情,请参阅标签生命周期。
停用后,用户仍可通过 API 应用此标签。已应用此标签的位置和搜索结果中仍会显示此标签。已停用的标签可以删除。
如需停用已发布的标签,请对 labels
集合使用 disable
方法。
您还必须指定:
此示例使用 ID
停用正确的标签。
Python
service.labels().disable(
name='labels/ID',
body={
'use_admin_access': True
}).execute()
Node.js
service.labels.disable({
'resource': {
'use_admin_access': true
},
'name': 'labels/ID'
}, (err, res) => {
if (err) return console.error('The API returned an error: ' + err);
console.log(res);
});
标签的 State
为 DISABLED
,并且标签的修订版本 ID 会递增。用户可以通过 API 应用标签。不过,除非配置了 disabledPolicy
方法的 showInApply
属性,否则界面中不会显示已停用的标签。
启用标签
启用已停用的标签会将其恢复为已发布状态。这会基于当前已停用的已发布修订版本生成新的已发布修订版本。如果存在已停用的现有草稿修订版本,系统会基于该草稿创建一个新修订版本并启用该版本。如需了解详情,请参阅标签生命周期。
如需启用已停用的标签,请使用 enable
方法。
您还必须指定:
此示例使用 ID
来启用正确的标签。
Python
service.labels().enable(
name='labels/ID',
body={
'use_admin_access': True
}).execute()
Node.js
service.labels.enable({
'resource': {
'use_admin_access': true
},
'name': 'labels/ID'
}, (err, res) => {
if (err) return console.error('The API returned an error: ' + err);
console.log(res);
});
标签的 State
为 PUBLISHED
,并且标签的修订版本 ID 会递增。用户可以通过 API 查看标签并将其应用于文件。
删除标签
只能删除草稿标签和已停用的标签。删除标签后,先前应用该标签的所有实例(包括用户输入的所有相应字段值)将会永久删除并从这些云端硬盘文件中移除。
如需删除标签,您必须先将其停用,然后使用 delete
方法。
您还必须指定:
此示例使用 ID
删除正确的标签。
Python
response = service.labels().delete(
name='labels/ID',
useAdminAccess=True).execute()
Node.js
service.labels.delete({
'name': 'labels/ID',
'use_admin_access': true
}, (err, res) => {
if (err) return console.error('The API returned an error: ' + err);
console.log(res);
});
标签的 State
为 DELETED
,并且标签的修订版本 ID 会递增。标签无法应用,并且已删除的标签最终会被清除。如需了解详情,请参阅标签生命周期。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[],[],null,["# Disable, enable & delete a label\n\nThis page describes how to perform these tasks involving labels:\n\n- Disable a label\n- Enable a label\n- Delete a label\n\nDisable a label\n---------------\n\nDisabling a label results in a new disabled published revision based on the\ncurrent published revision. If there's a draft revision, a new disabled draft\nrevision is created based on the latest draft revision. Older draft revisions\nare deleted. For more information, see [Label\nlifecycle](/workspace/drive/labels/guides/label-lifecycle).\n\nOnce disabled, users can still apply this label through the API. The label still\nappears where it's already been applied and in your search results. A disabled\nlabel can be [deleted](#delete).\n\nTo disable a published label, use the\n[`disable`](/workspace/drive/labels/reference/rest/v2/labels/disable) method on the\n[`labels`](/workspace/drive/labels/reference/rest/v2/labels) collection.\n\nYou also must specify:\n\n- A [Label resource](/workspace/drive/labels/reference/rest/v2/labels#resource:-label)\n that represents every label. It contains a resource `Name` and `ID`, which\n is a globally unique identifier for the label.\n\n- `useAdminAccess` is `true` to use the user's administrator credentials. The\n server verifies that the user is an admin for the label before allowing\n access.\n\nThis example uses the `ID` to disable the correct label. \n\n### Python\n\n service.labels().disable(\n name='labels/\u003cvar translate=\"no\"\u003eID\u003c/var\u003e',\n body={\n 'use_admin_access': True\n }).execute()\n\n### Node.js\n\n service.labels.disable({\n 'resource': {\n 'use_admin_access': true\n },\n 'name': 'labels/\u003cvar translate=\"no\"\u003eID\u003c/var\u003e'\n }, (err, res) =\u003e {\n if (err) return console.error('The API returned an error: ' + err);\n console.log(res);\n });\n\nThe label has the [`State`](/workspace/drive/labels/reference/rest/v2/labels#state) of\n`DISABLED` and the label's revision ID is incremented. Users can apply the label\nthrough the API. However, a disabled label is not shown in a UI unless the\n`showInApply` property of the\n[`disabledPolicy`](/workspace/drive/labels/reference/rest/v2/labels#DisabledPolicy) method\nis configured.\n\nEnable a label\n--------------\n\nEnabling a disabled label restores it to its published state. It results in a\nnew published revision based on the current disabled published revision. If\nthere's an existing disabled draft revision, a new revision is created based on\nthat draft and is enabled. For more information, see [Label\nlifecycle](/workspace/drive/labels/guides/label-lifecycle).\n\nTo enable a disabled label, use the\n[`enable`](/workspace/drive/labels/reference/rest/v2/labels/enable) method.\n\nYou also must specify:\n\n- A [Label resource](/workspace/drive/labels/reference/rest/v2/labels#resource:-label)\n that represents every label. It contains a resource `Name` and `ID`, which\n is a globally unique identifier for the label.\n\n- `useAdminAccess` is `true` to use the user's administrator credentials. The\n server verifies that the user is an admin for the label before allowing\n access.\n\nThis example uses the `ID` to enable the correct label. \n\n### Python\n\n service.labels().enable(\n name='labels/\u003cvar translate=\"no\"\u003eID\u003c/var\u003e',\n body={\n 'use_admin_access': True\n }).execute()\n\n### Node.js\n\n service.labels.enable({\n 'resource': {\n 'use_admin_access': true\n },\n 'name': 'labels/\u003cvar translate=\"no\"\u003eID\u003c/var\u003e'\n }, (err, res) =\u003e {\n if (err) return console.error('The API returned an error: ' + err);\n console.log(res);\n });\n\nThe label has the [`State`](/workspace/drive/labels/reference/rest/v2/labels#state) of\n`PUBLISHED` and the label's revision ID is incremented. Users can view and apply\nthe label to files through the API.\n\nDelete a label\n--------------\n\nOnly draft and disabled labels can be deleted. When a label is deleted, all\ninstances where the label was previously applied, including any corresponding\nfield values entered by users, are permanently deleted and removed from those\nDrive files.\n\nTo delete a label, you must first disable it and then use the\n[`delete`](/workspace/drive/labels/reference/rest/v2/labels/delete) method.\n\nYou also must specify:\n\n- A [Label resource](/workspace/drive/labels/reference/rest/v2/labels#resource:-label)\n that represents every label. It contains a resource `Name` and `ID`, which\n is a globally unique identifier for the label.\n\n- `useAdminAccess` is `true` to use the user's administrator credentials. The\n server verifies that the user is an admin for the label before allowing\n access.\n\nThis example uses the `ID` to delete the correct label. \n\n### Python\n\n response = service.labels().delete(\n name='labels/\u003cvar translate=\"no\"\u003eID\u003c/var\u003e',\n useAdminAccess=True).execute()\n\n### Node.js\n\n service.labels.delete({\n 'name': 'labels/\u003cvar translate=\"no\"\u003eID\u003c/var\u003e',\n 'use_admin_access': true\n }, (err, res) =\u003e {\n if (err) return console.error('The API returned an error: ' + err);\n console.log(res);\n });\n\nThe label has the [`State`](/workspace/drive/labels/reference/rest/v2/labels#state) of\n`DELETED` and the label's revision ID is incremented. The label cannot be\napplied and deleted labels are eventually purged. For more information, see\n[Label lifecycle](/workspace/drive/labels/guides/label-lifecycle)."]]