파일에서 라벨 삭제하기

이 페이지에서는 단일 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입니다.