2

我尝试使用此 python 函数下载 Google Drive 文档(使用 Drive 应用程序)。它每次都跳到# 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 函数?

4

1 回答 1

2

您需要导出 Google Doc,而不是下载它。检查用于导出文件的 Google Drive 文档,您需要将您的 URL 替换为以下内容:

download_url = file['exportLinks']['text/html']
于 2013-02-05T15:33:38.477 回答