我尝试使用此python函数下载Google云端硬盘文档(使用云端硬盘应用)。它每次跳到# The file doesn't have any content stored on Drive
部分。
def download_file(service, drive_file):
"""Download a file's content.
Args:
service: Drive API service instance.
drive_file: Drive File instance.
Returns:
File's content if successful, None otherwise.
"""
download_url = drive_file.get('downloadUrl')
if download_url:
resp, content = service._http.request(download_url)
if resp.status == 200:
print 'Status: %s' % resp
return content
else:
print 'An error occurred: %s' % resp
return None
else:
# The file doesn't have any content stored on Drive.
return None
但是我从来没有得到GDrive文档的HTML内容。我的mime设置(HTML Mime类型)有问题,还是应该使用其他API函数?
答案 0 :(得分:2)
您需要导出Google文档,而不是下载它。查看Google Drive documentation for exporting files,您需要使用以下内容替换您的网址:
download_url = file['exportLinks']['text/html']