Reputation: 271
What is the best way to get all files contained in a folder using Google Drive API (OAuth2)?
For example, with Dropbox, it's just a simple query to (1 request):
https://api.dropbox.com/1/metadata/dropbox/{folder}
For Skydrive, it is:
https://apis.live.net/v5.0/{folder}
and then querying the upload_location
(2 requests).
According to the Google API Documentations, for Google Drive, it's possible to make request to
https://www.googleapis.com/drive/v2/files/{folder}/children
To get data so that data.items
containing ID of children. However, with this method, if the folder has n
files, then it requires to make n+1
requests (1 for getting lists of items, and n for each item).
I think that making n+1
requests for such basic task is too many. Is that the way Google Drive API designed, or is there a faster method of querying all files (with enough metadata) inside a folder?
Upvotes: 1
Views: 2694
Reputation: 7032
You can use the list endpoint and limit results to files having a given parent.
See https://developers.google.com/drive/v2/reference/files/list:
https://www.googleapis.com/drive/v2/files?q='id'+in+parents
This returns much more metaData than the children endpoint
Upvotes: 5
Reputation: 91
I'm no expert but it looks like the way you've described is the way the API is designed. Just from the https://developers.google.com/drive/v2/reference/children/list it looks like it you are intended to get a List of ChildrenReference's, then from each item in that you get its file ID, then use the files().get(fileID) function to get each file from there.
Upvotes: -1