ラベルの無効化、有効化、削除
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このページでは、ラベルに関連する次のタスクを行う方法について説明します。
- ラベルを無効にする
- ラベルを有効にする
- ラベルを削除する
ラベルを無効にする
ラベルを無効にすると、現在の公開済みリビジョンに基づいて、新しい無効の公開済みリビジョンが作成されます。下書きリビジョンがある場合は、最新の下書きリビジョンに基づいて、新しい無効な下書きリビジョンが作成されます。古いドラフト リビジョンは削除されます。詳細については、ラベルのライフサイクルをご覧ください。
無効にしても、ユーザーは 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
プロパティが構成されていない限り、無効なラベルは UI に表示されません。
ラベルを有効にする
無効なラベルを有効にすると、公開状態に戻ります。これにより、現在無効になっている公開済みリビジョンに基づいて、新しい公開済みリビジョンが作成されます。無効な下書きリビジョンが既存の場合、その下書きに基づいて新しいリビジョンが作成され、有効になります。詳細については、ラベルのライフサイクルをご覧ください。
無効にしたラベルを有効にするには、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 Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-29 UTC。
[null,null,["最終更新日 2025-08-29 UTC。"],[],[],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)."]]