Reputation: 48
What I am trying to do is to create a local file tree from Google Drive files (works like a cache), so I don't have to make an HTTP request every time I need a file info (quota is limited on Google API).
My best approach was to request all the files at once, so I have one giant File list without too many HTTP requests, and I can just link them to create the tree. It kind of works by doing some tricks with the files, but the problem is that I'm getting much more files than I need (9729 received and just 1764 useful), because I'm not being able to think of an efficient filter to the list service. I'm downloading all the files (including sharedWithMe, except for trash because there is an easy filter for it trashed = false
, also downloading only necessary fields) and it takes much longer than it would be necessary because of the unnecessary data.
I just wanted to get files that are under MyDrive (root) folder (there are some files that are sharedWithMe and are also under MyDrive, I can't simply ignore them by using q = 'me' in owner
). In other words, I just want to get the files that are in the root level, files that are children of files that are on the root level and so on. Any query that makes it? Or at least makes it more efficient?
Note: this is not a shared drive application.
Upvotes: 1
Views: 543
Reputation: 48
The best way I found to create the tree is:
q: mimeType = 'application/vnd.google-apps.folder'
) as usually there are less folders than files. trashed = false
can also be useful.q = 'mimeType != 'application/vnd.google-apps.folder' and (folderId1' in parents or 'folderId2 in parents or ... or 'folderIdN' in parents)
(watch out for too complex query error with too big body size [maybe over 25,000 characters, not sure]).By doing so, there will be some useless data and a few requests, but the amount of downloaded data is much less than listing files without any q
restriction.
The idea came from Alternative 3 on the answer for this question.
Upvotes: 1