python - 无法下载 native Google Drive 文档的 HTML

标签 python google-drive-api google-api-python-client

我尝试使用此 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/

相关文章:

python - 使用 App Engine 服务帐户时出现链接损坏错误

python - 为 Google Admin SDK 创建和设置自定义属性

python - python 中的触摸条支持

python - 如何部署机器学习模型以使用多个特征数据进行预测

Python - Matplotlib 使用 pandas 数据框时绘制不正确的图形

google-docs - Google Apps 域 : drive migrator

python - Python 3 中的 re.findall

google-drive-api - Google Drive API v3 的导出链接

去阅读谷歌电子表格

python - 如何在Google Drive中搜索特定文件?