-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_doc.py
More file actions
29 lines (24 loc) · 893 Bytes
/
create_doc.py
File metadata and controls
29 lines (24 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from google.oauth2 import service_account
from googleapiclient.discovery import build
SCOPES = ['https://www.googleapis.com/auth/documents']
SERVICE_ACCOUNT_FILE = 'path/to/your/service-account-file.json'
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
service = build('docs', 'v1', credentials=credentials)
# Create a Document
document = service.documents().create(body={'title': 'New Document'}).execute()
document_id = document.get('documentId')
print(f'Document ID: {document_id}')
# Modifying the Document
requests = [
{
'insertText': {
'location': {
'index': 1,
},
'text': 'Hello, world!'
}
}
]
result = service.documents().batchUpdate(documentId=document_id, body={'requests': requests}).execute()
print(document)