Reputation: 2869
In v2 it was possible to make a call to /files
with the query fileId in children
to get a list of DriveFile
objects that were parents of the supplied file.
Now, it seems to be required to make a call to /files/:fileId?fields=parents
, then make a separate call to /files/:parentId
for each returned parent, possibly turning one call into a dozen.
Is this correct, and if so why? This is a huge performance hit to our app, so hopefully there's an undocumented method.
Upvotes: 4
Views: 10898
Reputation: 2529
EDIT: Okay I didn't read the original thoroughly, it seems they are trying to do something different from me. I'm trying to recurse drive files with as few requests as possible so I want to fetch all the level 1-2-3... folders' contents in a single request. And it's possible.
I posted this on the Google bug tracker but I'll post it here as well.
The API is clunky but it works. For fetching drives from Shared Drives, you must set "corpora" to "drive", "driveId" and "includeItemsFromAllDrives" as true. For fetching from My Drive you need "'me' in owners" in the "q" query and for Shared With Me "not 'me' in owners".
Then, you concatenate the parent ids with eg:
if (folderIds.length > 0) {
params.q = `${params.q} and ('${folderIds.join("' in parents or '",)}' in parents)`;
}
The result will be a big-ass string but it should work. Probably in cases it might yield 431 due to too long search parameters but so far so good.
Upvotes: 0
Reputation: 57
you just need to mention like below:
var request = service.Files.List();
request.Q = "('root' in parents)";
var FileListOfParentOnly = request.Execute();
Upvotes: 2
Reputation: 514
In V3 it is possible to list all children of a parent as it's explained here: https://developers.google.com/drive/v3/web/search-parameters
Example call:
https://www.googleapis.com/drive/v3/files?q=parents in '0Byho0qAdzabmVl8xcDR1S0pNY3c'
of course replace spaces with %20
, this will list all the files in the folder which has id='0Byho0qAdzabmVl8xcDR1S0pNY3c'
Upvotes: 2
Reputation: 11672
The query "'fileId' in children'" doesn't publicly exist (not documented/supported) in v2 either and I don't recall it ever existing. What does exist in V2 is the Parents collection which effectively answers the same question. In v3, to get the parents of a file you just get the child and ask for the parents field.
As for whether or not that is a performance hit, I don't think it is in practice. The Parents resource in v2 was very light to begin with, and other than the ID the only useful field was the 'isRoot' property. That you can calculate yourself by calling files/root up front to get the ID of the root folder for that user (just once and save it, it won't change for that user.)
If you need to get more information about the parents than just the IDs and are worried about the # of calls you have to make, use batching to fetch them. If you just have one parent, no need to batch (it's just overhead.) If you find that a file has multiple parents, create a batch request. That'll be sent as a single HTTP request/response and is handled very efficiently on the back end.
Point is, if you just need IDs, it's no worse than before. It's one call to get the parents of a file.
If you need more than IDs, it's at most 2 HTTP requests (outside really bizarre edge cases like 1000+ parents which would exceed the batch size :)
Upvotes: 3