Reputation: 49
I am working on a Google Drive API project with PHP, and I want to show the Title of the folder in which the user is browsing in a breadcrumb for example: Start -> Subfolder
I am using this code to recover files from a folder:
$optParams = array(
'pageSize' => 999,
'fields' => "nextPageToken, files",
'q' => "'".$folderId."' in parents"
);
$results = $service->files->listFiles($optParams);
But how do I get the title of the folder? Any suggestions?
Thanks!
Upvotes: 1
Views: 2982
Reputation: 201643
I could understand like above. But I'm not sure whether you want to retrieve the folder names in a specific folder or you want to retrieve the folder name from $folderId
. So I would like to propose 2 patterns as follows.
In this pattern, the folders in a specific folder are retrieved. From the result, you can retrieve the folder names.
$optParams = array(
'pageSize' => 999,
'fields' => 'nextPageToken, files',
'q' => "'".$folderId."' in parents and mimeType = 'application/vnd.google-apps.folder'"
);
$results = $service->files->listFiles($optParams);
and mimeType = 'application/vnd.google-apps.folder'
to the search query, only folders can be retrieved.In this pattern, the folder is retrieved from $folderId
. From the result, you can retrieve the folder names.
$results = $service->files->get($folderId);
printf("%s\n", $results->getName());
If I misunderstood your question and this was not the direction you want, I apologize.
When you want to retrieve the folder ID from the folder name, please use the following script.
$folderName = "folderName"; // Please set the folder name here.
$optParams = array(
'pageSize' => 10,
'fields' => 'nextPageToken, files',
'q' => "name = '".$folderName."' and mimeType = 'application/vnd.google-apps.folder'"
);
$results = $service->files->listFiles($optParams);
Upvotes: 2