設定檔案的標籤欄位

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

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

ModifyLabelsRequest 包含 LabelModification 也就是對檔案中的標籤修改可能也包含執行個體 / FieldModification 這會修改標籤欄位

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

範例

以下程式碼範例說明如何使用文字欄位的 fieldId 進行設定 這個 Field 的值。 檔案。初次為檔案設定標籤 Field 時,它會將該標籤套用到 檔案。接著,您可以取消單一欄位的設定,或是移除所有相關聯的欄位 標籤。詳情請參閱取消設定標籤欄位的 檔案,以及從群組移除標籤 檔案。

Java

LabelFieldModification fieldModification =
new LabelFieldModification().setFieldId("FIELD_ID").setSetTextValues(ImmutableList.of("VALUE"));

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','setTextValues':['VALUE']}
label_modification = {'labelId':'LABEL_ID', 'fieldModifications':[field_modification]}

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

Node.js

/**
* Set a label with a text field on a Drive file
* @return{obj} updated label data
**/
async function setLabelTextField() {
  // 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',
    'setTextValues': ['VALUE'],
  };
  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
  • VALUE:這個欄位的新 value
  • LABEL_ID:要修改的標籤的 labelId
  • FILE_ID:要加上標籤的檔案 fileId 已修改。

附註

  • 如要設定不含任何欄位的標籤,請套用無欄位的 labelModifications 目前已有 fieldModifications 人。
  • 如要設定選項欄位選項的值,請使用 值的 Choice ID 方法是從 Drive Labels API
  • 只有支援值清單的 Field 才能設定多個值。 否則您會收到 400: Bad Request 錯誤回應。
  • 為所選 Field 設定適當的值類型 (例如整數、文字、 使用者等),否則您會收到 400: Bad Request 錯誤回應。 您可以使用 Drive Labels API