Thanks for stopping by to let us know something could be better!
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Please run down the following list and make sure you've tried the usual "quick fixes":
If you are still having issues, please be sure to include as much information as possible:
googleapis version: ^39.2.0The "q" parameter is not returning the files in a folder when using the next query "'folder-id' in parents", although when using axios or the Try this API works as intended.
const queryFolders = (drive) => {
// Return the Promise result after completing its task
return new Promise((resolve, reject) => {
// Call Files: list endpoint
return drive.files.list({
"q": "'folder-id' in parents",
"fields": 'kind, files(id, name)'
},(err, results) => err ? reject(err) : resolve(results))
}
);
}
Making sure to follow these steps will guarantee the quickest resolution possible.
Thanks!
@elgatovielma :wave: thanks for the bug report 馃憤 sounds like you have a workaround for the time being?
@bcoe, Thank you for answering! Yes, as a workaround I used axios as in the following code:
const queryFoldersWithAxios = async () => {
const dummyData = [{id: "folder-id-1"}, {id: "folder-id-2"}];
const params = {
q: dummyData.map(folder => `'${folder.id}' in parents`).join(' or ')
};
const headers = {
"Authorization": "Bearer <YOUR_ACCESS_TOKEN>",
"Content-Type": "application/json"
}
return await axios.get("https://www.googleapis.com/drive/v3/files", {params, headers})
}
The access token I got it from OAuth 2.0 Playground for testing purposes.
FWIW: I tried the workaround above and I was getting the same issue I had previously.
As described in the S.O. post, my issue was drive.google.list not returning files found within any of my folders I had in my query, using the same query elgatovielma is using: '<folder-id-1>' in parents or '<folder-id-2>' in parents or.... Instead of receiving a list of all files in either of the specified folders, I either was returned an empty array of files, or an array of files populated with one item, a single folder.
However, as of tonight when I had the chance to glance at my S.O. post and this issue that elgato kindly created, thank you for that, I noticed more inconsistent and unusual behavior that drive.google.list was returning.
Folder contents
'A' in parents or 'B' in parentsThe following query of two folders, both only containing images returned** a list that contained only one item, the first image in folder 'A'. The result was not intended, expecting all files found in 'A' or in 'B'. What was missing was the rest of the images found in 'A' and all the images found in 'B'.
'B' in parents or 'A' in parentsThe following is identical to Query 1 except that the ordering of the query is swapped. The result is the same, returning the first image in folder 'A'. The result was not intended, expecting all files found in 'B' or in 'A'. What was missing was the rest of the images found in 'A' and all the images found in 'B'.
'A' in parents or 'C' in parentsThe following is a query of two folders, one containing only images, and the other containing one folder and the rest as images. The result of files was one image and one folder. The result was not intended, expecting all files found in 'A' or in 'C'. What was missing was the rest of the images found in 'A' and all the images in 'C'.
'C' in parents or 'D' in parentsThe following is a query of two folders, both containing only one folder and the rest of the files as images. The result of files was the two respective folders contained within each of the queried folders. The result was not intended, expecting all files found in 'C' or in 'D'. What was missing was all the images found in either 'C' or 'D'.
'A' in parents or 'E' in parentsThe following is a query of two folders, one containing only images, and the other containing only 7 folders. The result of files was one image and 7 folders. The result was not intended, expecting all images found in 'A' and all folders in 'E'. What was missing was the rest of the images found in A.
'C' in parents or 'E' in parentsThe following is a query of two folders, one containing one folder and the rest as images, and the other containing only 7 folders. The result of files was 8 folders. The result was not intended, expecting all images and the single folder in C and all folders in E. What was missing was all the images found in C.
The following results of the queries above is leading me on to believe that google.drive.list is behaving as such:
I really hope this helps in solving this issue. I have attached to this reply a horribly organized and _written_ list of my queries along with the actual folders I am querying in case the person attempting to solve this issue want to see for themselves the contents.
google-drive-list bug - Queries.txt
Should
"q": "'folder-id' in parents",
be:
"q": "'${folder-id}' in parents",
or:
"q": "'" + folder-id +"' in parents",
I use the latter, and it works
@mattcobb if I'm following correctly, the issue is simply that you need additional quotes around the folder-id?
folder-id is variable containing the parent ID, right? You want the value of folder-id to be expanded inside single quotes so q becomes, for example "'1muYqa15XxOEDIk4xXIZrOaOKZTWTc0bb' in parents". Currently, if I read that code correctly, it is literally the string "'folder-id' in parents" without the value of folder-id being used.
@elgatovielma I believe @mattcobb has correctly pointed out that the problem was simply that folder ID should be a variable, as follows:
const queryFolders = (drive) => {
// Return the Promise result after completing its task
return new Promise((resolve, reject) => {
// Call Files: list endpoint
return drive.files.list({
"q": `'${folder.id}' in parents`,
"fields": 'kind, files(id, name)'
},(err, results) => err ? reject(err) : resolve(results))
}
);
}
Just like in your axios example.
I'm closing this issue now as part of triage, please let me know if I've misunderstood 馃憤