53

I am trying to build a web UI for users to navigate his/her Google Drive and select one or more documents to be referenced later on in a website from a DB. I am currently building a web interface using .NET. The problem I am facing is that I can not find a single function to get a list of files by folder Id. I tried using:

...www.googleapis.com/drive/v2/files/BB0CHANGEDIDF5waGdzbUQ5aWs/children

…but that will only give the files reference ID of the files within the folder (the so called children resource item), which means I have to loop through those files and create a call for each one of them in order to get all the metadata I need for my UI. Unfortunately..

...www.googleapis.com/drive/v2/files

..will list ALL my files with no filtering options by folder. I would like to know if there is an efficient way of extracting a folder& file list from a single call to the Drive server by for a specific folder.

I also tried this (based on answer to the similar issue): I am using Fiddler to do direct calls to the api. When I use this to make the call `

...www.googleapis.com/drive/v2/files?q='BB0CHANGEDIDF5waGdzbUQ5aWs'

I get an error:

{
 "error": {
  "errors": [
   {wrongID
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid Value",
    "locationType": "parameter",
    "location": "q"
   }
  ],
  "code": 400,
  "message": "Invalid Value"
 }
}

Even using google's test page does not do it. It looks like the "files" endpoint does not accept any parameter.

There has to be a way to achieve this!

Thank you for your help

Community
  • 1
  • 1
user3199365
  • 633
  • 1
  • 6
  • 8

3 Answers3

56

You should be able to simply use files/list with a parent query;

GET https://www.googleapis.com/drive/v2/files?q='BB0CHANGEDIDF5waGdzbUQ5aWs'+in+parents&key={YOUR_API_KEY}
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
  • 1
    THANK YOU for your URL request string sample. The problem was that I was missing the: +in+parents Can you tell me where this "in parents" add is documented? I completely missed it. – user3199365 Jul 13 '14 at 13:56
  • @user3199365 It's documented [here](https://developers.google.com/drive/web/search-parameters), just search the page for "parents". – Joachim Isaksson Jul 14 '14 at 16:21
  • 3
    q='root' in parents will get you the top level folder, in case you were wondering – RoccoB Jul 25 '16 at 02:14
  • 4
    any documentation to api v3 please ? – zac Jan 31 '18 at 23:03
  • Closest thing to docs I could find is https://developers.google.com/drive/api/guides/search-files, but it doesn't explain what `parents` really is... – Jaap Sep 30 '22 at 09:16
19

Here's how to get specific fields of files in a folder using v3 API:

https://www.googleapis.com/drive/v3/files?q="folderId"+in+parents&fields=files(md5Checksum,+originalFilename)
//

Replace "folderId" with the folder ID.

You can use &fields=files(*) to get all of the file's fields.

XP1
  • 6,910
  • 8
  • 54
  • 61
19

If you're doing this on javascript with v3, try this on the request body:

{
  q: `'${folderId}' in parents`
}

However, this could also list the files from this folder that were deleted and are in the bin.So, you can do it like this:

{
  q: `'${folderId}' in parents and trashed = false`
}
Jesús Vera
  • 321
  • 2
  • 5