如何将字段参数传递到谷歌驱动器的python API调用 [英] How to pass the fields parameter into a google drive python API call

查看:131
本文介绍了如何将字段参数传递到谷歌驱动器的python API调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  results = drive_service.files()。list(** body).execute()

其中:

  body = {
'q':query_string,
'maxResults':1,
}

为了提高性能,我想限制返回的字段,如下所述: https://developers.google.com/drive/performance#partial-response



如果我只是添加 'fields':'id,items,title,mimeType' to body 我得到一个错误。我不确定如何添加该限制?



有点相关,python api会自动gzip请求吗?

解决方案

try:

  results = drive_service.files()。list(fields ='items(id,mimeType,title)',** body).execute()

可以使用API​​ Explorer轻松找出字段值应该是什么样子:



https://developers.google.com/apis-explorer/#p/drive/v2/drive.files.list

p>

是的,这些请求会自动进行压缩。您可以打开http流量记录来确认。请参阅:

https://developers.google.com/api-client-library/python/guide/logging


I have:

results = drive_service.files().list(**body).execute()

where:

body = {
    'q': query_string,
    'maxResults': 1,
}

To improve performance I would like to limit the fields returned as described here: https://developers.google.com/drive/performance#partial-response

if i just add 'fields': 'id,items,title,mimeType' to body i get an error. I'm not sure how to add that limitation?

Somewhat related, does the python api automatically gzip the request?

解决方案

try:

results = drive_service.files().list(fields='items(id,mimeType,title)', **body).execute()

you can easily figure out what the fields value should look like using API Explorer:

https://developers.google.com/apis-explorer/#p/drive/v2/drive.files.list

yes, the requests are automatically gzipped. You can turn on http traffic logging to confirm. see:

https://developers.google.com/api-client-library/python/guide/logging

这篇关于如何将字段参数传递到谷歌驱动器的python API调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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