문서 작성 및 관리

이 Google Docs API 페이지에서는 특정 상위 수준의 작업을 수행하는 방법에 대해 설명합니다. Google Docs 문서 및

  • 문서 새로 만들어 줘
  • 기존 문서 복사

다음 단락에서는 이러한 작업을 자세히 설명합니다.

빈 문서 만들기

문서를 만들려면 documents.create 메서드 documents 컬렉션입니다.

다음 코드 샘플은 지정된 제목:

자바

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 API를 추가해야 합니다. 승인하려는 범위를 있습니다. Drive 범위에 대한 자세한 내용은 선택 Google Drive API 범위

공유 드라이브 폴더 내에서 파일을 이동하거나 만들려면 공유 드라이브 구현하기를 참고하세요. 드라이브 지원을 참조하세요.

기존 문서 복사

문서를 복사하려면 Drive API의 files.copy 메서드를 사용하여 지도 가장자리에 패딩을 추가할 수 있습니다.

다음 코드 샘플은 기존 문서를 복사하는 방법을 보여줍니다. 다음에서 확인할 수 있습니다. 문서 URL에서 Drive API 호출에 사용할 ID입니다. 자세히 알아보기 자세한 내용은 문서 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 범위