Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get list of files by folder on Google Drive API

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

like image 381
user3199365 Avatar asked Jul 13 '14 06:07

user3199365


People also ask

How do I get a list of files in a Google Drive folder?

Goto the same Google Sheets File and refresh the page. Then you will get the "List Files/Folders" menu, click on it, and select the "List All Files and Folders" item.

How do I view files in Google Drive as a list?

To switch from grid view to list view, open Google Drive and press the List view button. Note: Smartbar features are available in the Google Drive file preview for Google files and non-Google files. You can access the file preview directly from grid mode.

Is Pydrive deprecated?

Deprecated. This project is deprecated and no longer maintained. No further changes will be made.


Video Answer


2 Answers

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} 
like image 161
Joachim Isaksson Avatar answered Sep 28 '22 11:09

Joachim Isaksson


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.

like image 33
XP1 Avatar answered Sep 28 '22 13:09

XP1