停用、啟用 &刪除標籤
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁面說明如何執行下列標籤相關工作:
停用標籤
停用標籤會根據目前發布的修訂版本,產生新的已停用發布修訂版本。如果存在草稿修訂版本,系統會根據最新的草稿修訂版本,建立新的停用草稿修訂版本。系統會刪除較舊的草稿修訂版本。詳情請參閱「標籤生命週期」。
停用後,使用者仍可透過 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 會遞增。標籤無法套用,且刪除的標籤最終會遭到清除。詳情請參閱「標籤生命週期」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間: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)."]]