파일에서 라벨 삭제하기

이 페이지에서는 하나의 Google Drive 파일에서 라벨을 삭제하는 방법을 설명합니다.

파일에서 파일 라벨 메타데이터를 삭제하려면 files.modifyLabels 메서드를 사용합니다. 요청 본문에는 파일의 라벨 집합을 수정하기 위한 ModifyLabelsRequest의 인스턴스가 포함됩니다. 요청에는 원자적으로 적용되는 여러 수정사항이 포함될 수 있습니다. 즉, 수정사항이 유효하지 않으면 전체 업데이트가 실패하고 잠재적으로 종속된 변경사항은 적용되지 않습니다.

ModifyLabelsRequest에는 파일의 라벨 수정사항인 LabelModification의 인스턴스가 포함됩니다. 라벨 필드를 수정한 FieldModification 인스턴스도 포함될 수 있습니다. 파일에서 라벨을 삭제하려면 FieldModification.removeLabelTrue로 설정합니다.

성공하면 응답 본문에 요청에 의해 추가되거나 업데이트된 라벨이 포함됩니다. 이는 Label 유형의 modifiedLabels 객체 내에 있습니다.

다음 코드 샘플은 labelId에서 fileId로 라벨과 연결된 모든 필드를 삭제하는 방법을 보여줍니다. 예를 들어 라벨에 텍스트 필드와 사용자 필드가 모두 포함된 경우 라벨을 삭제하면 라벨과 연결된 텍스트 및 사용자 필드가 모두 삭제됩니다. 반면 텍스트 필드를 설정 해제하면 텍스트 필드가 라벨에서 삭제되지만 사용자 필드는 그대로 유지됩니다. 자세한 내용은 파일의 라벨 필드 설정 해제를 참고하세요.

Java

ModifyLabelsRequest modifyLabelsRequest =
  new ModifyLabelsRequest()
      .setLabelModifications(
          ImmutableList.of(
              new LabelModification()
                .setLabelId("LABEL_ID")
                .setRemoveLabel(true)));

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

Python

label_modification = {'labelId':'LABEL_ID', 'removeLabel': True]}

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

Node.js

/**
* Remove a label on a Drive file
* @return{obj} updated label data
**/
async function removeLabel() {
  // 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 labelModification = {
    'labelId': 'LABEL_ID',
    'removeLabel': True,
  };
  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;
  }

다음을 바꿉니다.

  • LABEL_ID: 수정할 라벨의 labelId입니다. 파일에서 라벨을 찾으려면 files.listLabels 메서드를 사용합니다.
  • FILE_ID: 라벨이 수정된 파일의 fileId입니다.