从Dri以编程方式下载exportLink

2024-03-28 22:14:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从谷歌文档中下载某个修订版。从Drive REST API v2中,我得到了以下链接:

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

这是我第一次这样做,我完全迷路了。这和身份验证有关吗?我打算做的是最终将.txt文件放在我的电脑中

我试着用这个,但没有成功:

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())

我得到的是:

200
b''

可能我没有考虑很多概念,欢迎任何类型的帮助(在任何编程语言中)。你知道吗

谢谢


Tags: httpstxtcomiddocsresponsedownloadgoogle
1条回答
网友
1楼 · 发布于 2024-03-28 22:14:56

要获取修订版本的导出链接,请使用revisions.list。该代码与其他驱动器文档一样包含在指南中。修订.列表将返回调用revisions.get时所需的一组修订ID。你知道吗

以下是指南中的一个片段:

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

是的,你需要得到授权和认证才能执行这个调用。你知道吗

相关问题 更多 >