Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass the fields parameter into a google drive python API call

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?

like image 404
rsp Avatar asked Dec 21 '12 20:12

rsp


3 Answers

API v2:

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

API v3:

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

https://developers.google.com/apis-explorer/#p/drive/v3/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

like image 109
Jay Lee Avatar answered Oct 18 '22 09:10

Jay Lee


try

body = {
    'q': query_string,
    'maxResults': 1,
    'fields': 'items/id, items/title, items/mimeType',
}

or

body = {
    'q': query_string,
    'fields': 'items(id,title,mimeType),nextPageToken',  # if you need to get full result
}
like image 40
clsung Avatar answered Oct 18 '22 09:10

clsung


I had similar problem, the problem was in api version.

like image 2
matoni Avatar answered Oct 18 '22 09:10

matoni