PyDrive2 icon indicating copy to clipboard operation
PyDrive2 copied to clipboard

docs: How to get specific fields when listing files.

Open Cing2 opened this issue 4 years ago • 10 comments

Hey,

How is it going with this project? I am planning to use this for my own project and was trying some things. However I could not find how to get certain fields of a file, like id, name, parents. etc.. The documentation also isn't clear this one. I am willing to help with the project, to get it more usable. Love to hear from you.

Regards,

Cing2 avatar Jun 02 '20 19:06 Cing2

@Cing2

How is it going with this project?

it is actively maintained, at least as long as `iterative/dvc is alive and maintained.

However I could not find how to get certain fields of a file, like id, name, parents. etc

I assume you already found the file listing API - https://pythonhosted.org/PyDrive/filelist.html#file-listing-made-easy right? Then it already has a small example how to get title and id (and the same way you can access other file attributes). Am I missing something in your question?

shcheklein avatar Jun 02 '20 20:06 shcheklein

Yes, I can see how get the attributes after the download. But how do you select to only download the attributes you need. Which will reduce data and time needed. https://developers.google.com/drive/api/v3/reference/files/list in the docs you can have an parameter 'fields', to select the attributes you need.

Cing2 avatar Jun 02 '20 20:06 Cing2

Have you tried to pass param={"fields": ...} to the list call? .. I think it should support it as well.

shcheklein avatar Jun 02 '20 22:06 shcheklein

Yes I did but got an ApiRequestError. This is what I tried:

file_list = drive.ListFile({'fields': 'id, name',
                            'q': "'root' in parents and trashed=false"}).GetList()

Cing2 avatar Jun 03 '20 10:06 Cing2

Try this: 'fields': 'items(id,title)' - check the API docs for the exact syntax on how to specify the list of fields you'd like to get.

shcheklein avatar Jun 03 '20 20:06 shcheklein

Thank you, I see now that you are still using the v2 version. Although this is not clear on the home page.

Cing2 avatar Jun 03 '20 20:06 Cing2

Yes, but I think the syntax for fields is the same across v2 and v3 - check these examples https://developers.google.com/drive/api/v3/fields-parameter

shcheklein avatar Jun 03 '20 20:06 shcheklein

Ah oke, I was looking at this one: https://developers.google.com/drive/api/v3/search-files

Cing2 avatar Jun 03 '20 23:06 Cing2

@Cing2 sure. I keep it open with the documentation label. Hopefully we'll get a contribution to improve it and put some examples.

shcheklein avatar Jun 03 '20 23:06 shcheklein