2
votes

I want to download a certain revision from a Google Document. From the Drive REST API v2 I got the following link:

https://docs.google.com/feeds/download/documents/export/Export?id=XXXXX&revision=1&exportFormat=txt

It's the first time I do something like this, I'm completely lost. Does it have something to do with authentication? What I'm intending to do is to finally have the .txt file in my PC.

I tried using this, without success:

http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED', ca_certs=certifi.where())
url = 'https://docs.google.com/feeds/download/documents/export/Export?id=XXXXX&revision=1&exportFormat=txt'
response = http.request('GET', url)
print(response.status)
print(response.read())

What I got is:

200
b''

Probably I'm not taking into account a lot of concepts, any kind of help is welcome (in any programming language).

Thanks

1

1 Answers

0
votes

To get the export link of the revision version, use the revisions.list. The code is included in the guide as with other Drive docs. revisions.list will return a bunch of revision ids which you will need when making a call to revisions.get.

Here's a snippet from the guide:

from apiclient import errors
# ...

def print_revision(service, file_id, revision_id):
  """Print information about the specified revision.

  Args:
    service: Drive API service instance.
    file_id: ID of the file to print revision for.
    revision_id: ID of the revision to print.
  """
  try:
    revision = service.revisions().get(
        fileId=file_id, revisionId=revision_id).execute()

    print 'Revision ID: %s' % revision['id']
    print 'Modified Date: %s' % revision['modifiedDate']
    if revision.get('pinned'):
      print 'This revision is pinned'
  except errors.HttpError, error:
    print 'An error occurred: %s' % error

And yes, you need to be authorized and authenticated to perform this calls.