파일의 라벨 필드 설정
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
이 페이지에서는 단일 Google Drive 파일에 Field
라벨을 설정하는 방법을 설명합니다.
파일 라벨을 설정하여 파일에 메타데이터를 추가하려면 files.modifyLabels
메서드를 사용합니다. 요청 본문에는 파일의 라벨 집합을 수정하는 ModifyLabelsRequest
인스턴스가 포함됩니다. 요청에는 원자적으로 적용되는 수정사항이 여러 개 포함될 수 있습니다. 즉, 수정사항이 유효하지 않으면 전체 업데이트가 실패하고 (잠재적으로 종속된) 변경사항이 적용되지 않습니다.
ModifyLabelsRequest
에는 파일의 라벨 수정사항인 LabelModification
인스턴스가 포함되어 있습니다. 라벨 필드의 수정사항인 FieldModification
인스턴스도 포함될 수 있습니다.
성공하면 응답 본문에 요청에 의해 추가되거나 업데이트된 라벨이 포함됩니다. 이러한 항목은 Label
유형의 modifiedLabels
객체 내에 있습니다.
예
다음 코드 샘플은 텍스트 필드의 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]}).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
입니다.
참고
- 필드가 없는 라벨을 설정하려면
fieldModifications
이 없는 labelModifications
을 적용합니다.
- 선택 필드 옵션의 값을 설정하려면 Drive Labels API에서 라벨 스키마를 가져와 확인할 수 있는 값의
Choice
ID를 사용하세요.
- 값 목록을 지원하는
Field
만 여러 값을 설정할 수 있습니다. 그렇지 않으면 400: Bad Request
오류 응답이 표시됩니다.
- 선택한
Field
에 적합한 값 유형 (예: 정수, 텍스트, 사용자 등)을 설정해야 합니다. 그렇지 않으면 400: Bad Request
오류 응답이 수신됩니다.
Drive Labels API를 사용하여 필드 데이터 유형을 검색할 수 있습니다.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-29(UTC)
[null,null,["최종 업데이트: 2025-08-29(UTC)"],[],[],null,["# Set a label field on a file\n\nThis page describes how to set a label\n[`Field`](/workspace/drive/labels/reference/rest/v2/labels#field) on a single\nGoogle Drive file.\n\nTo add metadata to a file by setting a file label, use the\n[`files.modifyLabels`](/workspace/drive/api/v2/reference/files/modifyLabels) method. The\n[request body](/workspace/drive/api/reference/rest/v2/files/modifyLabels#request-body)\ncontains an instance of\n[`ModifyLabelsRequest`](/workspace/drive/api/reference/rest/v2/files/modifyLabels#modifylabelsrequest)\nto modify the set of labels on a file. The request might contain several\nmodifications that are applied atomically. That is, if any modifications aren't\nvalid, then the entire update is unsuccessful and none of the (potentially\ndependent) changes are applied.\n\nThe `ModifyLabelsRequest` contains an instance of\n[`LabelModification`](/workspace/drive/api/reference/rest/v2/files/modifyLabels#labelmodification)\nwhich is a modification to a label on a file. It might also contain an instance\nof\n[`FieldModification`](/workspace/drive/api/reference/rest/v2/files/modifyLabels#fieldmodification)\nwhich is a modification to a label's field.\n\nIf successful, the [response\nbody](/workspace/drive/api/reference/rest/v2/files/modifyLabels#response-body) contains\nthe labels added or updated by the request. These exist within a\n`modifiedLabels` object of type [`Label`](/workspace/drive/api/reference/rest/v2/Label).\n\nExample\n-------\n\nThe following code sample shows how to use the `fieldId` of a text field to set\na value for this [`Field`](/workspace/drive/labels/reference/rest/v2/labels#field) on a\nfile. When a label `Field` is initially set on a file, it applies the label to\nthe file. You can then unset a single field or remove all fields associated with\nthe label. For more information, see [Unset a label field on a\nfile](/workspace/drive/api/guides/unset-label) and [Remove a label from a\nfile](/workspace/drive/api/guides/remove-label). \n\n### Java\n\n LabelFieldModification fieldModification =\n new LabelFieldModification().setFieldId(\"\u003cvar translate=\"no\"\u003eFIELD_ID\u003c/var\u003e\").setSetTextValues(ImmutableList.of(\"\u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e\"));\n\n ModifyLabelsRequest modifyLabelsRequest =\n new ModifyLabelsRequest()\n .setLabelModifications(\n ImmutableList.of(\n new LabelModification()\n .setLabelId(\"\u003cvar translate=\"no\"\u003eLABEL_ID\u003c/var\u003e\")\n .setFieldModifications(ImmutableList.of(fieldModification))));\n\n ModifyLabelsResponse modifyLabelsResponse = driveService.files().modifyLabels(\"\u003cvar translate=\"no\"\u003eFILE_ID\u003c/var\u003e\", modifyLabelsRequest).execute();\n\n### Python\n\n field_modification = {'fieldId':'\u003cvar translate=\"no\"\u003eFIELD_ID\u003c/var\u003e','setTextValues':['\u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e']}\n label_modification = {'labelId':'\u003cvar translate=\"no\"\u003eLABEL_ID\u003c/var\u003e', 'fieldModifications':[field_modification]}\n\n modified_labels = drive_service.files().modifyLabels(fileId=\"\u003cvar translate=\"no\"\u003eFILE_ID\u003c/var\u003e\", body = {'labelModifications' : [label_modification]}).execute()\n\n### Node.js\n\n /**\n * Set a label with a text field on a Drive file\n * @return{obj} updated label data\n **/\n async function setLabelTextField() {\n // Get credentials and build service\n // TODO (developer) - Use appropriate auth mechanism for your app\n\n const {GoogleAuth} = require('google-auth-library');\n const {google} = require('googleapis');\n\n const auth = new GoogleAuth({scopes: 'https://www.googleapis.com/auth/drive'});\n const service = google.drive({version: 'v3', auth});\n const fieldModification = {\n 'fieldId': '\u003cvar translate=\"no\"\u003eFIELD_ID\u003c/var\u003e',\n 'setTextValues': ['\u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e'],\n };\n const labelModification = {\n 'labelId': '\u003cvar translate=\"no\"\u003eLABEL_ID\u003c/var\u003e',\n 'fieldModifications': [fieldModification],\n };\n const labelModificationRequest = {\n 'labelModifications': [labelModification],\n };\n try {\n const updateResponse = await service.files.modifyLabels({\n fileId: '\u003cvar translate=\"no\"\u003eFILE_ID\u003c/var\u003e',\n resource: labelModificationRequest,\n });\n return updateResponse;\n } catch (err) {\n // TODO (developer) - Handle error\n throw err;\n }\n }\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eFIELD_ID\u003c/var\u003e: The `fieldId` of the field to modify. To locate the `fieldId`, retrieve the label using the [Google Drive Labels API](/workspace/drive/labels/guides/search-label).\n- \u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e: The new `value` for this field.\n- \u003cvar translate=\"no\"\u003eLABEL_ID\u003c/var\u003e: The `labelId` of the label to modify.\n- \u003cvar translate=\"no\"\u003eFILE_ID\u003c/var\u003e: The `fileId` of the file for which the labels are modified.\n\nNotes\n-----\n\n- To set a label with no fields, apply `labelModifications` with no `fieldModifications` present.\n- To set values for selection field options, use the [`Choice`](/workspace/drive/labels/reference/rest/v2/labels#choice) id of the value that you can get by fetching the label schema in the [Drive Labels API](/workspace/drive/labels/guides/overview).\n- Only a `Field` that supports lists of values can have multiple values set, otherwise you'll receive a `400: Bad Request` error response.\n- Set the proper value type for the selected `Field` (such as integer, text, user, etc.), otherwise you'll receive a `400: Bad Request` error response. You can retrieve the field data type using the [Drive Labels API](/workspace/drive/labels/reference/rest/v2/labels#field)."]]