简体   繁体   中英

List All Folders and their files in Google Drive SDK

I am using Google Drive SDK to get a list of my files and display them on my site! I am using a service account for server-side integration!

I have like 4-5 folders in my root directory and 50-60 files in each of them! What scopes should I use and what method should I use so as to retrieve all the folders and then their sub files?

I cant seem to find documentation for getting folders or so! In v2 it was by using childrens method but PHP SDK is on v3.

My flow would be like this.

Authenticate using service acccount->get list of folders->get list of files inside this folder->display them.

First make sure you understand that a Service Account is not your personal Google account . So unless you share all your folders, you will not be able to access your files by authenticating using a Service Account. See How do I authorise an app (web or installed) without user intervention? (canonical ?)

Once you are authenticating using the correct credentials. The best approach is to:-

  1. Authenticate using your own credentials
  2. List all of your folders files.list q='mimetype=application/vnd.google-apps.folder and trashed=false
  3. For those folder ids you wish to see the children files.list q=parents in (id1, id2,...) and trashed = false

See How do I search sub-folders and sub-sub-folders in Google Drive? for some background on how folders work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM