Is there any way to get a list of all folders in "My Drive" using the Google Drive API. Here is the function I am trying to write.
function getAllFolders(){
// Get all folders
}
(I looked at some other stack overflow posts but they weren't very helpful for me).
With the query string q
, you can search for files and folders following the syntax in the documentation
Using mimeType = 'application/vnd.google-apps.folder'
in the query string, to get just the folders.
there is a simple exemple:
<?php
$service = new Google_Service_Drive($client);
$folderID = "root";
$optParams = array(
'pageSize' => 100,
'fields' => 'nextPageToken, files(id, name, mimeType, modifiedTime, size, parents)',
'q' => "mimeType = 'application/vnd.google-apps.folder' and '".$folderID."' in parents"
);
$results = $service->files->listFiles($optParams);
foreach ($results as $file) {
// do somethings
}
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.