Google Docs gets an API for task automation
FYI the Python quickstart.py is broken on Ubuntu 18.04 (tried both python2 and python3). I&#x27;ve notified the eng in the video, and sent her here.<p>By definition, credentials.json doesn&#x27;t exist yet and this throws an error. Transcript below.<p><pre><code>    creds = None
    if os.path.exists(&#x27;token.pickle&#x27;):
        ...
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            ...
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                &#x27;credentials.json&#x27;, SCOPES)
            creds = flow.run_local_server()

</code></pre>
<a href="https:&#x2F;&#x2F;developers.google.com&#x2F;docs&#x2F;api&#x2F;quickstart&#x2F;python" rel="nofollow">https:&#x2F;&#x2F;developers.google.com&#x2F;docs&#x2F;api&#x2F;quickstart&#x2F;python</a><p>$ sudo apt install python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  grub-pc-bin libpython-all-dev libpython-dev libpython2.7 libpython2.7-dev python-all python-all-dev python-asn1crypto python-cffi-backend python-crcmod python-crypto python-cryptography
  python-dbus python-dev python-enum34 python-gi python-idna python-ipaddress python-keyring python-keyrings.alt python-secretstorage python-six python-wheel python-xdg python2.7-dev
Use &#x27;sudo apt autoremove&#x27; to remove them.
The following NEW packages will be installed:
  python3-pip
0 upgraded, 1 newly installed, 0 to remove and 11 not upgraded.
Need to get 114 kB of archives.
After this operation, 599 kB of additional disk space will be used.
Get:1 <a href="http:&#x2F;&#x2F;us-east4-c.gce.clouds.archive.ubuntu.com&#x2F;ubuntu" rel="nofollow">http:&#x2F;&#x2F;us-east4-c.gce.clouds.archive.ubuntu.com&#x2F;ubuntu</a> bionic-updates&#x2F;universe amd64 python3-pip all 9.0.1-2.3~ubuntu1 [114 kB]
Fetched 114 kB in 1s (175 kB&#x2F;s)
Selecting previously unselected package python3-pip.
(Reading database ... 128010 files and directories currently installed.)
Preparing to unpack ...&#x2F;python3-pip_9.0.1-2.3~ubuntu1_all.deb ...
Unpacking python3-pip (9.0.1-2.3~ubuntu1) ...
Setting up python3-pip (9.0.1-2.3~ubuntu1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...<p>$ pip3 install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
Collecting google-api-python-client
  Downloading <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;55&#x2F;e9&#x2F;e8fb2e3a031cb69b9524b80a92b126665d9a17421700a219555e3233ab6a&#x2F;google_api_python_client-1.7.8-py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;55&#x2F;e9&#x2F;e8fb2e3a031cb6...</a> (56kB)
    100% || 61kB 3.1MB&#x2F;s
Collecting google-auth-httplib2
  Using cached <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;33&#x2F;49&#x2F;c814d6d438b823441552198f096fcd0377fd6c88714dbed34f1d3c8c4389&#x2F;google_auth_httplib2-0.0.3-py2.py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;33&#x2F;49&#x2F;c814d6d438b823...</a>
Collecting google-auth-oauthlib
  Using cached <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;46&#x2F;df&#x2F;d1f94ee2cffe5a83721f262efe51f3b2dcdd3b616caf007b8490e824c550&#x2F;google_auth_oauthlib-0.2.0-py2.py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;46&#x2F;df&#x2F;d1f94ee2cffe5a...</a>
Collecting six&lt;2dev,&gt;=1.6.1 (from google-api-python-client)
  Using cached <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;73&#x2F;fb&#x2F;00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9&#x2F;six-1.12.0-py2.py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;73&#x2F;fb&#x2F;00a976f728d0d1...</a>
Collecting httplib2&lt;1dev,&gt;=0.9.2 (from google-api-python-client)
  Using cached <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;ce&#x2F;ed&#x2F;803905d670b52fa0edfdd135337e545b4496c2ab3a222f1449b7256eb99f&#x2F;httplib2-0.12.0.tar.gz" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;ce&#x2F;ed&#x2F;803905d670b52f...</a>
Collecting uritemplate&lt;4dev,&gt;=3.0.0 (from google-api-python-client)
  Downloading <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;e5&#x2F;7d&#x2F;9d5a640c4f8bf2c8b1afc015e9a9d8de32e13c9016dcc4b0ec03481fb396&#x2F;uritemplate-3.0.0-py2.py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;e5&#x2F;7d&#x2F;9d5a640c4f8bf2...</a>
Collecting google-auth&gt;=1.4.1 (from google-api-python-client)
  Using cached <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;4e&#x2F;85&#x2F;71b2dfbf5b4241cd031cc333ed71f90a271074a97cb2c517bb65f07a1a90&#x2F;google_auth-1.6.2-py2.py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;4e&#x2F;85&#x2F;71b2dfbf5b4241...</a>
Collecting requests-oauthlib&gt;=0.7.0 (from google-auth-oauthlib)
  Using cached <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;c2&#x2F;e2&#x2F;9fd03d55ffb70fe51f587f20bcf407a6927eb121de86928b34d162f0b1ac&#x2F;requests_oauthlib-1.2.0-py2.py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;c2&#x2F;e2&#x2F;9fd03d55ffb70f...</a>
Collecting cachetools&gt;=2.0.0 (from google-auth&gt;=1.4.1-&gt;google-api-python-client)
  Using cached <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;39&#x2F;2b&#x2F;d87fc2369242bd743883232c463f28205902b8579cb68dcf5b11eee1652f&#x2F;cachetools-3.1.0-py2.py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;39&#x2F;2b&#x2F;d87fc2369242bd...</a>
Collecting pyasn1-modules&gt;=0.2.1 (from google-auth&gt;=1.4.1-&gt;google-api-python-client)
  Using cached <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;da&#x2F;98&#x2F;8ddd9fa4d84065926832bcf2255a2b69f1d03330aa4d1c49cc7317ac888e&#x2F;pyasn1_modules-0.2.4-py2.py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;da&#x2F;98&#x2F;8ddd9fa4d84065...</a>
Collecting rsa&gt;=3.1.4 (from google-auth&gt;=1.4.1-&gt;google-api-python-client)
  Using cached <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;02&#x2F;e5&#x2F;38518af393f7c214357079ce67a317307936896e961e35450b70fad2a9cf&#x2F;rsa-4.0-py2.py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;02&#x2F;e5&#x2F;38518af393f7c2...</a>
Collecting oauthlib&gt;=3.0.0 (from requests-oauthlib&gt;=0.7.0-&gt;google-auth-oauthlib)
  Using cached <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;16&#x2F;95&#x2F;699466b05b72b94a41f662dc9edf87fda4289e3602ecd42d27fcaddf7b56&#x2F;oauthlib-3.0.1-py2.py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;16&#x2F;95&#x2F;699466b05b72b9...</a>
Collecting requests&gt;=2.0.0 (from requests-oauthlib&gt;=0.7.0-&gt;google-auth-oauthlib)
  Using cached <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;7d&#x2F;e3&#x2F;20f3d364d6c8e5d2353c72a67778eb189176f08e873c9900e10c0287b84b&#x2F;requests-2.21.0-py2.py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;7d&#x2F;e3&#x2F;20f3d364d6c8e5...</a>
Collecting pyasn1&lt;0.5.0,&gt;=0.4.1 (from pyasn1-modules&gt;=0.2.1-&gt;google-auth&gt;=1.4.1-&gt;google-api-python-client)
  Using cached <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;7b&#x2F;7c&#x2F;c9386b82a25115cccf1903441bba3cbadcfae7b678a20167347fa8ded34c&#x2F;pyasn1-0.4.5-py2.py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;7b&#x2F;7c&#x2F;c9386b82a25115...</a>
Collecting urllib3&lt;1.25,&gt;=1.21.1 (from requests&gt;=2.0.0-&gt;requests-oauthlib&gt;=0.7.0-&gt;google-auth-oauthlib)
  Using cached <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;62&#x2F;00&#x2F;ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e&#x2F;urllib3-1.24.1-py2.py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;62&#x2F;00&#x2F;ee1d7de624db8b...</a>
Collecting certifi&gt;=2017.4.17 (from requests&gt;=2.0.0-&gt;requests-oauthlib&gt;=0.7.0-&gt;google-auth-oauthlib)
  Using cached <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;9f&#x2F;e0&#x2F;accfc1b56b57e9750eba272e24c4dddeac86852c2bebd1236674d7887e8a&#x2F;certifi-2018.11.29-py2.py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;9f&#x2F;e0&#x2F;accfc1b56b57e9...</a>
Collecting chardet&lt;3.1.0,&gt;=3.0.2 (from requests&gt;=2.0.0-&gt;requests-oauthlib&gt;=0.7.0-&gt;google-auth-oauthlib)
  Using cached <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;bc&#x2F;a9&#x2F;01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8&#x2F;chardet-3.0.4-py2.py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;bc&#x2F;a9&#x2F;01ffebfb562e42...</a>
Collecting idna&lt;2.9,&gt;=2.5 (from requests&gt;=2.0.0-&gt;requests-oauthlib&gt;=0.7.0-&gt;google-auth-oauthlib)
  Using cached <a href="https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;14&#x2F;2c&#x2F;cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9&#x2F;idna-2.8-py2.py3-none-any.whl" rel="nofollow">https:&#x2F;&#x2F;files.pythonhosted.org&#x2F;packages&#x2F;14&#x2F;2c&#x2F;cd551d81dbe152...</a>
Building wheels for collected packages: httplib2
  Running setup.py bdist_wheel for httplib2 ... done
  Stored in directory: &#x2F;home&#x2F;asah&#x2F;.cache&#x2F;pip&#x2F;wheels&#x2F;6d&#x2F;41&#x2F;4b&#x2F;2b369d6e2b7eaebcdd423516d3fb659c7658c16a2be8fd04ec
Successfully built httplib2
Installing collected packages: six, httplib2, cachetools, pyasn1, pyasn1-modules, rsa, google-auth, google-auth-httplib2, uritemplate, google-api-python-client, oauthlib, urllib3, certifi, chardet, idna, requests, requests-oauthlib, google-auth-oauthlib
Successfully installed cachetools-3.1.0 certifi-2018.11.29 chardet-3.0.4 google-api-python-client-1.7.8 google-auth-1.6.2 google-auth-httplib2-0.0.3 google-auth-oauthlib-0.2.0 httplib2-0.12.0 idna-2.8 oauthlib-3.0.1 pyasn1-0.4.5 pyasn1-modules-0.2.4 requests-2.21.0 requests-oauthlib-1.2.0 rsa-4.0 six-1.12.0 uritemplate-3.0.0 urllib3-1.24.1<p>$ python quickstart.py
InstalledAppFlow.from_client_secrets_file()...
Traceback (most recent call last):
  File &quot;quickstart.py&quot;, line 47, in &lt;module&gt;
    main()
  File &quot;quickstart.py&quot;, line 32, in main
    &#x27;credentials.json&#x27;, SCOPES)
  File &quot;&#x2F;home&#x2F;asah&#x2F;.local&#x2F;lib&#x2F;python2.7&#x2F;site-packages&#x2F;google_auth_oauthlib&#x2F;flow.py&quot;, line 171, in from_client_secrets_file
    with open(client_secrets_file, &#x27;r&#x27;) as json_file:
IOError: [Errno 2] No such file or directory: &#x27;credentials.json&#x27;<p>$ cat quickstart.py
from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request<p># If modifying these scopes, delete the file token.pickle.
SCOPES = [&#x27;<a href="https:&#x2F;&#x2F;www.googleapis.com&#x2F;auth&#x2F;documents.readonly&#x27;" rel="nofollow">https:&#x2F;&#x2F;www.googleapis.com&#x2F;auth&#x2F;documents.readonly&#x27;</a>]<p># The ID of a sample document.
DOCUMENT_ID = &#x27;195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE&#x27;<p>def main():
    &quot;&quot;&quot;Shows basic usage of the Docs API.
    Prints the title of a sample document.
    &quot;&quot;&quot;
    creds = None
    # The file token.pickle stores the user&#x27;s access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    if os.path.exists(&#x27;token.pickle&#x27;):
        with open(&#x27;token.pickle&#x27;, &#x27;rb&#x27;) as token:
            creds = pickle.load(token)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            print(&quot;InstalledAppFlow.from_client_secrets_file()...&quot;)
            flow = InstalledAppFlow.from_client_secrets_file(
                &#x27;credentials.json&#x27;, SCOPES)
            creds = flow.run_local_server()
        # Save the credentials for the next run
        with open(&#x27;token.pickle&#x27;, &#x27;wb&#x27;) as token:
            pickle.dump(creds, token)<p><pre><code>    service = build(&#x27;docs&#x27;, &#x27;v1&#x27;, credentials=creds)

    # Retrieve the documents contents from the Docs service.
    document = service.documents().get(documentId=DOCUMENT_ID).execute()

    print(&#x27;The title of the document is: {}&#x27;.format(document.get(&#x27;title&#x27;)))

</code></pre>
if __name__ == &#x27;__main__&#x27;:
    main()