简体   繁体   中英

Is there any way to list only files that are on root folder or any level under it on Google Drive API with one request?

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 thelist 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 .

The best way I found to create the tree is:

  1. request a files.list for all the folders ( q: mimeType = 'application/vnd.google-apps.folder' ) as usually there are less folders than files. trashed = false can also be useful.
  2. Create the tree structure discarding all of the useless folders.
  3. For each folder in the tree, get their id and then file.list with 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]).
  4. Complete the linking of the tree.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM