2

この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 関数を使用する必要がありますか?

4

1 に答える 1

2

Google ドキュメントをダウンロードするのではなく、エクスポートする必要があります。ファイルのエクスポートについては、Google ドライブのドキュメントを確認してください。URL を次のように置き換える必要があります。

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