use Google\Client;
use Google\Service\Drive;
function searchFiles()
{
try {
$client = new Client();
$client->useApplicationDefaultCredentials();
$client->addScope(Drive::DRIVE);
$driveService = new Drive($client);
$files = array();
$pageToken = null;
do {
$response = $driveService->files->listFiles(array(
'q' => "mimeType='image/jpeg'",
'spaces' => 'drive',
'pageToken' => $pageToken,
'fields' => 'nextPageToken, files(id, name)',
));
foreach ($response->files as $file) {
printf("Found file: %s (%s)\n", $file->name, $file->id);
}
array_push($files, $response->files);
$pageToken = $response->pageToken;
} while ($pageToken != null);
return $files;
} catch(Exception $e) {
echo "Error Message: ".$e;
}
}