I am using this code to get files but how can I access folders and their contents as well their children the documentation is not covering this.
`$client->setAccessToken ($this->getAccessToken ());
$drive = new Google_Service_Drive($client);
return Response::json (($files = $drive->files->listFiles ()));`
Hi,
You have to first list folders, and then explore each folder for files.
The trick to list only folders is to set the q query parameter with the right mimetype :
$drive->files->listFiles(array('q' => "trashed = false AND mimeType='application/vnd.google-apps.folder'"));
The response here will only contain folders in your drive account. Then process in a loop each of this folders to find its files, thanks to the parents property : we select only files having $folder->id as a parent. Said otherwise, we select only $folder->id childs :
// loop content here
$drive->files->listFiles(array('q' => "trashed = false AND '{$folder->id} IN parents' "));
// endloop content
Looks like your question was answered by helpful community members. Thanks community! Please feel free re-open if I misread the thread.
Most helpful comment
Hi,
You have to first list folders, and then explore each folder for files.
The trick to list only folders is to set the
qquery parameter with the rightmimetype:The response here will only contain folders in your drive account. Then process in a loop each of this folders to find its files, thanks to the
parentsproperty : we select only files having$folder->idas a parent. Said otherwise, we select only$folder->idchilds :