2

I have lots of sub-folders and here is my code for searching

"trashed = false 
AND ( ".$folderIds." ) 
AND mimeType != 'application/vnd.google-apps.folder'"

where the $folderIds are the subfolders, ex:

0B_123dSaMpleFolderId1 in parents or 0B_123dSaMpleFolderId2 in parents and 300 more folders

I know that limits are already posted here: What is the limit on Google Drive API usage?

but I would like to know the limits for this.. of how long should the parameter be when sending it to google drive api

Limit on search query parameter

FritzB
  • 335
  • 3
  • 14
  • my guess is the limit is a lot less than you'll need for 300 folders. You should find another approach, eg. add all the files to a single additional folder that you can search for. – pinoyyid Apr 20 '15 at 05:10
  • that would be an option thanks.. but it would be great if there is an option to put only the parent folder id and google drive api will do the rest of searching on the subfolders.. – FritzB Apr 20 '15 at 05:37
  • I really wanted to do the search in one request but unfortunately in my case its not possible.. so what I did is divide the number of folders.. I ended up doing 3-4 requests per search.. I think it wouldn't hurt the quota of 10M per day.. – FritzB Apr 21 '15 at 04:38
  • remember that in Drive "folders" aren't really folders, they are labels. So you can have files in folder-1, folder-2, etc *and* in folder-master. So you only need to query for folder-master in parents. – pinoyyid Apr 21 '15 at 05:52
  • I tried that, if you specify the parent folder it will only search on the first level.. it won't go inside folder-1 or folder-2 – FritzB Apr 21 '15 at 10:42
  • 1
    I think you misunderstand me. folder-master is not the parent of folder-1. In Drive, folders are simply labels and a file can have multiple labels. So, for example, file-1 is labelled folder-1 *and* folder-master. Likewise, file-2 is labelled folder-2 *and* folder-master. Now you only need query folder-master. – pinoyyid Apr 21 '15 at 13:43
  • I get you now.. what I need to do now is add all files to a specific folder that will be used for searching.. thanks @pinoyyid – FritzB Apr 22 '15 at 09:51

1 Answers1

3

The Google Drive API v3 allowed me to search within 598 folders:

len(gdrive.search(
    f"mimeType!='application/vnd.google-apps.folder' and 
    ({build_folder_subquery(folders[0:598])})"
))

713

but not 599:

len(gdrive.search(
    f"mimeType!='application/vnd.google-apps.folder' and 
    ({build_folder_subquery(folders[0:599])})"
))
*** googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/drive/v3/files returned "The query is too complex.">

I don't know whether the 'query is too complex' error is triggered by the number of operators in the query, by the number of characters in the query, or by some other measure. The number of characters in the queries above are 29949 and 29999.

gatherer
  • 333
  • 1
  • 2
  • 9
  • Thought I'd add to this, the max query length I am being cut off at is 7340 characters. Might have changes since your answer. – 010011100101 Jul 06 '21 at 08:41