파일의 라벨 필드 설정

이 페이지에서는 단일 Google Drive 파일에 Field 라벨을 설정하는 방법을 설명합니다. 파일 라벨을 설정하여 파일에 메타데이터를 추가하려면 files.modifyLabels 메서드를 사용합니다.

다음 항목도 지정해야 합니다.

  • 수정할 필드의 fieldId입니다.

  • 이 필드의 새 value입니다.

  • 수정할 라벨의 labelId입니다.

  • 라벨이 수정되는 파일의 fileId입니다.

이 예에서는 텍스트 필드의 fieldId를 사용하여 파일에서 이 Field의 값을 설정합니다. 파일에 Field 라벨을 처음 설정하면 라벨을 파일에 적용합니다. 그런 다음 단일 필드를 설정 취소하거나 라벨과 연결된 모든 필드를 삭제할 수 있습니다. 자세한 내용은 파일의 라벨 필드 설정 해제파일에서 라벨 삭제를 참고하세요.

자바

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]});

Node.js

/**
* Set a label with a text field on a Drive file
* @return{obj} updated label data
**/
async function modifyLabelTextField() {
  // 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;
  }
}

메모

  • 필드가 없는 라벨을 설정하려면 fieldModifications이 없는 labelModifications를 적용합니다.
  • 선택 필드 값을 설정하려면 Drive Drive Label API에서 라벨 스키마를 가져와 가져올 수 있는 값의 선택 ID를 사용합니다.
  • 값 목록을 지원하는 Field에만 여러 값을 설정할 수 있습니다. 그러지 않으면 400: Bad Request 오류 응답이 발생합니다.
  • fieldId을 찾으려면 Drive Drive Labels API를 사용하여 라벨을 검색하세요.
  • 선택한 field에 적절한 값 유형 (예: 정수, 텍스트, 사용자 등)을 설정하세요. 그렇지 않으면 400: Bad Request 오류 응답이 수신됩니다. Drive Drive Labels API를 사용하여 필드 데이터 유형을 검색할 수 있습니다.