문서 작성 및 관리
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
이 Google Docs API 페이지에서는 다음과 같은 Google Docs 문서와 관련된 특정 상위 수준 작업을 실행하는 방법을 설명합니다.
다음 단락에서는 이러한 작업을 자세히 설명합니다.
빈 문서 만들기
문서를 만들려면 documents
컬렉션에서 documents.create
메서드를 사용합니다.
다음 코드 샘플은 지정된 제목으로 빈 문서를 만드는 방법을 보여줍니다.
자바
private static void createDoc(Docs service) throws IOException {
Document doc = new Document()
.setTitle("My Document");
doc = service.documents().create(doc)
.execute();
System.out.println("Created document with title: " + doc.getTitle());
}
PHP
$title = 'My Document';
$document = new Google_Service_Docs_Document(array(
'title' => $title
));
$document = $service->documents->create($document);
printf("Created document with title: %s\n", $document->title);
Python
title = 'My Document'
body = {
'title': title
}
doc = service.documents() \
.create(body=body).execute()
print('Created document with title: {0}'.format(
doc.get('title')))
Google Drive 폴더로 작업하기
Docs API를 사용하여 지정된 Drive 폴더 내에서 직접 문서를 만드는 방법은 없습니다. 기본적으로 생성된 문서는 Drive의 사용자 루트 폴더에 저장됩니다.
하지만 파일을 Drive 폴더에 저장하는 방법에는 두 가지 대안이 있습니다.
문서를 만든 후 Drive API의 files.update
메서드를 사용하여 특정 폴더로 이동합니다. 파일 이동에 대한 자세한 내용은 폴더 간 파일 이동을 참고하세요.
Drive API의 files.create
메서드를 사용하여 폴더에 빈 문서를 추가하고 mimeType
로 application/vnd.google-apps.document
를 지정합니다. 파일 만들기에 대한 자세한 내용은 특정 폴더에 파일 만들기를 참고하세요.
두 대안 모두 호출을 승인하려면 적절한 Drive API 범위를 추가해야 합니다. Drive 범위에 대한 자세한 내용은 Google Drive API 범위 선택하기를 참고하세요.
공유 드라이브 폴더 내에서 파일을 이동하거나 만들려면 공유 드라이브 지원 구현을 참고하세요.
기존 문서 복사
문서를 복사하려면 Drive API의 files.copy
메서드를 사용합니다.
다음 코드 샘플은 기존 문서를 복사하는 방법을 보여줍니다. Drive API 호출에 사용할 ID는 문서 URL에서 확인할 수 있습니다. 자세한 내용은 문서 ID를 참고하세요.
https://docs.google.com/document/d/DOCUMENT_ID/edit
자바
String copyTitle = "Copy Title";
File copyMetadata = new File().setName(copyTitle);
File documentCopyFile =
driveService.files().copy(documentId, copyMetadata).execute();
String documentCopyId = documentCopyFile.getId();
Node.js
var copyTitle = "Copy Title";
let request = {
name: copyTitle,
};
this.driveService.files.copy({
fileId: documentId,
resource: request,
}, (err, driveResponse) => {
let documentCopyId = driveResponse.id;
});
PHP
<?php
$copyTitle = 'Copy Title';
$copy = new Google_Service_Drive_DriveFile(array(
'name' => $copyTitle
));
$driveResponse = $driveService->files->copy($documentId, $copy);
$documentCopyId = $driveResponse->id;
Python
copy_title = 'Copy Title'
body = {
'name': copy_title
}
drive_response = drive_service.files().copy(
fileId=document_id, body=body).execute()
document_copy_id = drive_response.get('id')
호출을 승인하려면 적절한 Drive API 범위를 사용해야 합니다. Drive 범위에 대한 자세한 내용은 Google Drive API 범위 선택하기를 참고하세요.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-29(UTC)
[null,null,["최종 업데이트: 2025-08-29(UTC)"],[],[],null,["# Create and manage documents\n\nThis Google Docs API page describes how to perform certain high-level tasks\ninvolving Google Docs documents, such as:\n\n- Create a document\n- Copy an existing document\n\nThe following paragraphs describe these tasks in detail.\n\nCreate a blank document\n-----------------------\n\nTo create a document, use the\n[`documents.create`](/workspace/docs/api/reference/rest/v1/documents/create) method on the\n[`documents`](/workspace/docs/api/reference/rest/v1/documents) collection.\n\nThe following code sample shows how to create a blank document with a specified\ntitle: \n\n### Java\n\n\n```java\nprivate static void createDoc(Docs service) throws IOException {\n Document doc = new Document()\n .setTitle(\"My Document\");\n doc = service.documents().create(doc)\n .execute();\n System.out.println(\"Created document with title: \" + doc.getTitle());\n}\n```\n\n\u003cbr /\u003e\n\n### PHP\n\n\n```php\n$title = 'My Document';\n$document = new Google_Service_Docs_Document(array(\n 'title' =\u003e $title\n));\n\n$document = $service-\u003edocuments-\u003ecreate($document);\nprintf(\"Created document with title: %s\\n\", $document-\u003etitle);\n```\n\n\u003cbr /\u003e\n\n### Python\n\n\n```python\ntitle = 'My Document'\nbody = {\n 'title': title\n}\ndoc = service.documents() \\\n .create(body=body).execute()\nprint('Created document with title: {0}'.format(\n doc.get('title')))\n```\n\n\u003cbr /\u003e\n\n### Work with Google Drive folders\n\nThere's no option to create a document directly within a specified\nDrive folder using the Docs API. By default, the\ncreated document is saved to the user's root folder on Drive.\n\nHowever, there are two alternatives to saving a file to a Drive\nfolder:\n\n- After the document is created, move it to a specific folder using\n Drive API's\n [`files.update`](/workspace/drive/api/v3/reference/files/update) method. For\n more information on moving files, see [Move files between\n folders](/workspace/drive/api/guides/folder#move-files).\n\n- Add a blank document to a folder using the Drive API's\n [`files.create`](/workspace/drive/api/v3/reference/files/create) method,\n specifying `application/vnd.google-apps.document` as the `mimeType`. For\n more information on creating files, see [Create a file in a specific\n folder](/workspace/drive/api/guides/folder#create-file).\n\nFor either alternative, you'll need to add the appropriate [Drive API\nscopes](/workspace/drive/api/v3/reference/files/create#authorization-scopes) to\nauthorize the call. For more information on Drive scopes, see\n[Choose Google Drive API scopes](/workspace/drive/api/guides/api-specific-auth).\n\nTo move or create a file within a shared drive folder, see [Implement shared\ndrive support](/workspace/drive/api/guides/enable-shareddrives).\n\nCopy an existing document\n-------------------------\n\nTo copy a document, use Drive API's\n[`files.copy`](/workspace/drive/v3/reference/files/copy) method.\n\nThe following code sample shows how to copy an existing document. You can find\nthe ID to use for the Drive API call in the document URL. For more\ninformation, see\n[Document ID](/workspace/docs/api/concepts/document#document-id). \n\n https://docs.google.com/document/d/\u003cvar translate=\"no\"\u003eDOCUMENT_ID\u003c/var\u003e/edit\n\n### Java\n\n\n```java\nString copyTitle = \"Copy Title\";\nFile copyMetadata = new File().setName(copyTitle);\nFile documentCopyFile =\n driveService.files().copy(documentId, copyMetadata).execute();\nString documentCopyId = documentCopyFile.getId();\n```\n\n\u003cbr /\u003e\n\n### Node.js\n\n\n```javascript\nvar copyTitle = \"Copy Title\";\nlet request = {\n name: copyTitle,\n};\nthis.driveService.files.copy({\n fileId: documentId,\n resource: request,\n}, (err, driveResponse) =\u003e {\n let documentCopyId = driveResponse.id;\n});\n```\n\n\u003cbr /\u003e\n\n### PHP\n\n\n```php\n\u003c?php\n$copyTitle = 'Copy Title';\n$copy = new Google_Service_Drive_DriveFile(array(\n 'name' =\u003e $copyTitle\n));\n$driveResponse = $driveService-\u003efiles-\u003ecopy($documentId, $copy);\n$documentCopyId = $driveResponse-\u003eid;\n```\n\n\u003cbr /\u003e\n\n### Python\n\n\n```python\ncopy_title = 'Copy Title'\nbody = {\n 'name': copy_title\n}\ndrive_response = drive_service.files().copy(\n fileId=document_id, body=body).execute()\ndocument_copy_id = drive_response.get('id')\n```\n\n\u003cbr /\u003e\n\nNote that you need to use an appropriate [Drive API\nscope](/workspace/drive/v3/reference/files/copy#authorization-scopes)\nto authorize the call. For more information on Drive scopes, see\n[Choose Google Drive API scopes](/workspace/drive/api/guides/api-specific-auth).\n\nRelated topics\n--------------\n\n- [Insert, delete, and move text](/workspace/docs/api/how-tos/move-text)\n- [Merge text into a document](/workspace/docs/api/how-tos/merge)\n- [Document concepts](/workspace/docs/api/concepts/document)"]]