40
votes

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

3
Yes, there API docs are horrible :(CpILL

3 Answers

46
votes

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}
16
votes

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.

8
votes

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`
}