如何将fields参数传递给google驱动器python API调用

rsp*_*rsp 4 python google-drive-api

我有:

results = drive_service.files().list(**body).execute()
Run Code Online (Sandbox Code Playgroud)

哪里:

body = {
    'q': query_string,
    'maxResults': 1,
}
Run Code Online (Sandbox Code Playgroud)

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

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

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

Jay*_*Lee 9

API v2:

results = drive_service.files().list(fields='items(id,mimeType,title)', **body).execute()
Run Code Online (Sandbox Code Playgroud)

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

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

API v3:

results = drive_service.files().list(fields='files(id,mimeType,name)', **body).execute()
Run Code Online (Sandbox Code Playgroud)

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

是的,请求会自动进行gzip压缩.您可以打开http流量记录进行确认.看到:

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