我尝试使用此 python 函数下载 Google Drive 文档(使用 Drive 应用程序)。它每次都会跳转到 # The file does not have any content store 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 函数?
最佳答案
您需要导出 Google 文档,而不是下载它。检查Google Drive documentation for exporting files ,您需要将您的 URL 替换为以下内容:
download_url = file['exportLinks']['text/html']
关于python - 无法下载 native Google Drive 文档的 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14710545/