如何在Google Drive Python API中使用alt = media? [英] How to use alt=media with Google Drive Python API?

查看:198
本文介绍了如何在Google Drive Python API中使用alt = media?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是一种方式(基于Google Drive Python quickstart.py)通过Python API从Google Drive下载文件:

 凭证= get_credentials()
HTTP = credentials.authorize(的httplib2.Http())
服务= discovery.build( '驱动', 'V2',HTTP = HTTP)

请求= service.files()。get_media(FILEID = FILE_ID)
FH = io.FileIO(FILE_NAME,把wb)
下载= MediaIoBaseDownload(FH,请求,CHUNKSIZE = 1024 * 1024)

做=假
虽然做的是假:
状态,做= downloader.next_chunk()
如果状态:
打印(下载进度:{}%。format(int(status.progress()* 100)))
print(download complete!)

这将带有文件ID file_id 的驱动器文件写入名为 file_name 的本地文件。 b

然而,文档说明了并且在那之上首选方法是使用alt = media。

alt = media如何处理文件().get()? alt =媒体去哪了?它有什么作用?



任何人都可以提供一个简单的例子来说明如何使用files().get()和alt = media? b
$ b

或者... <使用 files()。get() alt = media 只是表示使用文件().get_media()?!



感谢任何能够提供明确解释的人!

解决方案

Gerardo的评论很贴切,基本上我怀疑。案件结案。并感谢您指出OAuth Playground。


Here is one way (based on Google Drive Python quickstart.py) to download a file from Google Drive with the Python API:

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.

However, the documentation says over and over that the "preferred method" is to use "alt=media".

How does alt=media work with files().get() ? Where does alt=media go? What does it do?

Can anyone provide a simple example of how to download a file with files().get() and alt=media?

Or... does "use files().get() with alt=media" just mean use files().get_media() ?!

Thanks to anyone who can provide a clear explanation!

解决方案

Gerardo's comment is apt and basically what I suspected. Case closed. And thank you for pointing out the OAuth Playground.

这篇关于如何在Google Drive Python API中使用alt = media?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆