Reputation: 1
We are trying to incorporate Google Drive as a document repository for our application. We are using Google Drive API V3 for accessing Google Drive API. In this process, we are facing few challenges for implementing some of the features. The following are the constraints.
We are trying to retrieve the folders and files only inside a particular folder. But Currently we cannot able to achieve them.
When retrieving is there any provision to order files and folders in the exact hierarchy of how it is located in the Google Drive?
When retrieving the files and folders, we could able to see the folders and files which are deleted from drive already.
Could you please help us on how to achieve them.
Upvotes: 0
Views: 198
Reputation: 1197
Simple REST API request to: https://www.googleapis.com/drive/v3/files with q parametr, where you specify the query, what you want to search. For example:
mimeType = 'application/vnd.google-apps.folder' // list only folders
'root' in parents // only files (or folders) that are in root folder (have root in parents)
Complete guide here:
https://developers.google.com/drive/api/v3/search-files
Here you have playground, on the right side you can try the API:
https://developers.google.com/drive/api/v3/reference/files/list
The biggest issue for me was, how to pass these parameters to the URL, the magic is to encodeURIComponent (in javascript), so your complete URL gets from:
https://www.googleapis.com/drive/v3/files?q=mimeType = 'application/vnd.google-apps.folder' AND 'root' in parents
to
https://www.googleapis.com/drive/v3/files?q=mimeType%20%3D%20'application%2Fvnd.google-apps.folder'%20AND%20'root'%20in%20parents
And that will Google definitely understand. Don't forget to send your google token in Authorization header, e.g.:
headers: {
Authorization: `Bearer ${user.google_token}`,
'Content-Type': 'application/json',
},
Upvotes: 1