取消設定檔案的標籤欄位

本頁說明如何取消設定標籤 單一價格:Field Google 雲端硬碟檔案。

如要取消設定檔案標籤來移除檔案的中繼資料,請使用 files.modifyLabels 方法,增加圍繞地圖邊緣的邊框間距。 要求主體 包含 ModifyLabelsRequest敬上 修改檔案中的標籤組合。要求中可能含有數個 自動套用的修改也就是說,如果沒有任何修改 有效的更新,則整次更新會失敗,而且所有更新 (可能 才會套用變更

ModifyLabelsRequest 包含 LabelModification 也就是對檔案中的標籤修改可能也包含執行個體 / FieldModification敬上 這會修改標籤欄位如要取消設定欄位值, 將 FieldModification.unsetValues 設為 True

如果成功, body 包含 由要求所新增或更新的標籤這些存在於 Label 類型的 modifiedLabels 物件。

範例

以下程式碼範例說明如何使用 fieldIdlabelId 取消設定 關聯 fileId 中的欄位值。舉例來說,假設標籤中含有 文字和使用者欄位,但取消設定文字欄位會將該欄位從標籤中移除 但保留使用者欄位維持不變而移除標籤則會「同時」刪除 文字和使用者欄位若需更多資訊,請參閲 移除檔案的標籤

Java

LabelFieldModification fieldModification =
  new LabelFieldModification().setFieldId("FIELD_ID").setUnsetValues(true);

ModifyLabelsRequest modifyLabelsRequest =
  new ModifyLabelsRequest()
      .setLabelModifications(
          ImmutableList.of(
              new LabelModification()
                .setLabelId("LABEL_ID")
                .setFieldModifications(ImmutableList.of(fieldModification))));

ModifyLabelsResponse modifyLabelsResponse = driveService.files().modifyLabels("FILE_ID", modifyLabelsRequest).execute();

Python

field_modification = {'fieldId':'FIELD_ID','unsetValues':True}
label_modification = {'labelId':'LABEL_ID', 'fieldModifications':[field_modification]}

modified_labels = drive_service.files().modifyLabels(fileId="FILE_ID", body = {'labelModifications' : [label_modification]}).execute();

Node.js

/**
* Unset a label with a field on a Drive file
* @return{obj} updated label data
**/
async function unsetLabelField() {
  // Get credentials and build service
  // TODO (developer) - Use appropriate auth mechanism for your app

  const {GoogleAuth} = require('google-auth-library');
  const {google} = require('googleapis');

  const auth = new GoogleAuth({scopes: 'https://www.googleapis.com/auth/drive'});
  const service = google.drive({version: 'v3', auth});
  const fieldModification = {
    'fieldId': 'FIELD_ID',
    'unsetValues': True,
  };
  const labelModification = {
    'labelId': 'LABEL_ID',
    'fieldModifications': [fieldModification],
  };
  const labelModificationRequest = {
    'labelModifications': [labelModification],
  };
  try {
    const updateResponse = await service.files.modifyLabels({
      fileId: 'FILE_ID',
      resource: labelModificationRequest,
    });
    return updateResponse;
  } catch (err) {
    // TODO (developer) - Handle error
    throw err;
  }
}

更改下列內容:

  • FIELD_ID:要修改欄位的 fieldId。定位 fieldId,請使用 Google Drive Labels API
  • LABEL_ID:要修改的標籤 labelId
  • FILE_ID:要加上標籤的檔案 fileId 已修改。