File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from __future__ import print_function
2+ from apiclient import discovery
3+ from httplib2 import Http
4+ from oauth2client import client
5+ from oauth2client import file
6+ from oauth2client import tools
7+ import json
8+
9+ # Set doc ID, as found at `https://docs.google.com/document/d/YOUR_DOC_ID/edit`
10+ DOCUMENT_ID = YOUR_DOC_ID
11+
12+ # Set the scopes and discovery info
13+ SCOPES = 'https://www.googleapis.com/auth/documents.readonly'
14+ DISCOVERY_DOC = 'https://docs.googleapis.com/$discovery/rest?version=v1&key=<YOUR_API_KEY>'
15+
16+ # Initialize credentials and instantiate Docs API service
17+ store = file .Storage ('token.json' )
18+ creds = store .get ()
19+ if not creds or creds .invalid :
20+ flow = client .flow_from_clientsecrets ('credentials.json' , SCOPES )
21+ creds = tools .run_flow (flow , store )
22+ service = discovery .build ('docs' , 'v1' , http = creds .authorize (
23+ Http ()), discoveryServiceUrl = DISCOVERY_DOC )
24+
25+ # Do a document "get" request and print the results as formatted JSON
26+ result = service .documents ().get (documentId = DOCUMENT_ID ).execute ()
27+ print (json .dumps (result , indent = 4 , sort_keys = True ))
You can’t perform that action at this time.
0 commit comments