sharedWithMe field in files.list method returns Bad Request error 400 when sharedWithMe = false
See original GitHub issue//get all of the files within a given parent (folder) and mimeType
const getFiles = (auth, parent, mimeType) => {
return new Promise((resolve, reject) => {
let request = { //make the request header
auth: auth,
corpora: "user",
spaces: "drive",
includeTeamDriveItems: false,
q: "sharedWithMe = false"
}
if (parent) {
//backticks for template literals https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
request.q += ` and '${parent}' in parents` //get all the user's files with the given mimeType
}
if (mimeType) {
request.q += ` and mimeType = '${mimeType}'` //get all the user's files with the given parent
}
drive.files.list(request, (error, response) => { //call the api files.list method https://developers.google.com/drive/v3/reference/files/list
if (error) {
reject(error)
} else {
let files = {}
response.data.files.forEach(file => {
files[file.name] = file.id
})
resolve(files) //return an object with the name and id of the files
}
})
})
}
When calling the function getFiles like so (where auth is my OAuth2Client):
getFiles(auth).then((files) => {
console.log(files)
})
drives.files.list returns a Bad Request 400 error.
Changing request.q to “sharedWithMe = true” or even “sharedWithMe != false” returns the expected output.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to Fix a 400 Bad Request Error (Causes and Fixes) - Kinsta
The 400 Bad Request error indicates that the server cannot or process the request due to a client error. Read about the common...
Read more >query 'sharedWithMe=false' Invalid Value? - Stack Overflow
This is a bug. It seems that the documentation doesn't reflect the actual behavior for the sharedWithMe Search Query Term.
Read more >Solved: Move File - Bad Request - Power Platform Community
I always get a "Bad Request" with a status code of 400 when using the "Move File". The error details: Failed to verify...
Read more >Version News for Windows - GoodSync
Update news for GoodSync's Windows file sync and backup software. ... Fixed returning Error 518 'Direct Server is still computing response' in wrong...
Read more >NetSuite Applications Suite - Editing a Dataset
Item Search Displays Incorrect Results · Category Product Lists Return Page Not ... select Shared with me in the dropdown list of either...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you Justin for filing that bug and much appreciated for the tip. 😄
Apologies for the trouble! This looks like a bug with the underlying API. I can reproduce this pretty easily here: https://developers.google.com/drive/v3/reference/files/list
Sadly, that means there isn’t much I can do with it. I filed an internal bug in hopes of getting the issue cleared up, and I’ll report back here if there are any changes there.
On a side note - you don’t have to do all that song and dance for promises! We added native promise support in 28.1.0, so you can just do this:
Hope that helps 😃