简体   繁体   English

如何将alt = media与Google Drive Python API结合使用?

[英]How to use alt=media with Google Drive Python API?

Here is one way (based on Google Drive Python quickstart.py) to download a file from Google Drive with the Python API: 这是一种使用Python API从Google Drive下载文件的方法(基于Google Drive Python quickstart.py):

credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
service = discovery.build('drive', 'v2', http=http)

request = service.files().get_media(fileId=file_id)
fh = io.FileIO(file_name, 'wb')
downloader = MediaIoBaseDownload(fh, request, chunksize=1024*1024)

done = False
while done is False:
    status, done = downloader.next_chunk()
    if status:
        print("download progress: {} %".format(int(status.progress() * 100)))
print("download complete!")

This writes the Drive file with file ID file_id to a local file with name file_name . 这会将文件ID为file_id的Drive文件写入名称为file_name的本地文件。

However, the documentation says over and over that the "preferred method" is to use "alt=media". 但是, 文档一遍又一遍地说,“首选方法”是使用“ alt = media”。

How does alt=media work with files().get() ? alt = media如何与files()。get()一起使用? Where does alt=media go? alt = media在哪里? What does it do? 它有什么作用?

Can anyone provide a simple example of how to download a file with files().get() and alt=media? 谁能提供一个简单的示例,说明如何使用files()。get()和alt = media下载文件?

Or... does "use files().get() with alt=media " just mean use files().get_media() ?! 或者...“使用alt = media使用files()。get()只是意味着使用files()。get_media()吗?!

Thanks to anyone who can provide a clear explanation! 感谢任何能够提供清晰解释的人!

Gerardo's comment is apt and basically what I suspected. Gerardo的评论是恰当的,基本上是我所怀疑的。 Case closed. 案件结案。 And thank you for pointing out the OAuth Playground. 并感谢您指出OAuth游乐场。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM