以编程方式从驱动器下载exportLink
问题描述:
我想从Google文档下载某个修订版。从驱动器REST API V2我得到了以下链接:以编程方式从驱动器下载exportLink
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''
也许我没有考虑到很多概念,任何形式的帮助是值得欢迎(以任何编程语言)。
感谢
答
要获取的修订版的导出链接,使用revisions.list。代码与其他云端硬盘文档一样,也包含在本指南中。 revisions.list将返回一串修订ID,您在拨打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
是的,你需要进行授权和认证,以执行该调用。
感谢您的回应,正是我使用revisions.list得到了该链接,从而产生了像这样的https://developers.google.com/drive/v2/reference/revisions这样的JSON。不幸的是,我能得到该修订版的内容的唯一方法是将提供的链接插入到浏览器的地址栏中。我无法弄清楚如何用Python做这个任务,这就是为什么我用urllib3尝试失败。所需的结果是我的电脑中的.txt文件,我只能使用地址栏实现它:( –