Reputation: 64
I am thoroughly confused!
I am trying to do 3 things in php and Google Drive:
In the following line of code, I can successfully list folders and files (with help from examples on the net), but I can't seem to find documentation on lines like:
$results = $service->files->listFiles($optParams);
Which I believe is service/resource/method??
I had hoped that $results = $service->drives->driveList(); would show me shared drives, but to no avail.
Questions
The code below does successfully print files and folders, so I do know the authentication works.
Thank you for your help!
$client = new Google_Client();
$client->setClientId("xxxxxxxxxxxxxxxxxxx");
$client->setClientSecret("xxxxxxxxxxxxxxxxxxx");
$client->setRedirectUri("https://xxxxxxxxxxxxxxxxxxx.php");
$client->setScopes ( array ( 'https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/admin.directory.user.readonly', 'https://www.googleapis.com/auth/userinfo.email' ) );
$client->addScope("https://www.googleapis.com/auth/userinfo.profile");
$client->addScope("https://www.googleapis.com/auth/userinfo.email");
//$service = new Google_Service_Oauth2($client);
$service = new Google_Service_Drive($client);
print_r($_SESSION[access_token]);
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
// Print the names and IDs for up to 10 files from a particular drive.
$optParams = array(
'corpora' => 'drive',
'driveId' => 'xxxxxxxxxxxxxxxxxxx',
'includeItemsFromAllDrives' => true,
'pageSize' => 10,
'supportsAllDrives' => true,
'fields' => 'nextPageToken, files(id, name)'
);
$results = $service->files->listFiles($optParams);
// print results
foreach ($results->getFiles() as $file){
echo $file->getName()." ".$file->getId()."<br>";
}
//Print all folders from 'My Drive'
$optParams = array(
'fields' => 'nextPageToken, files(id, name, mimeType, modifiedTime, size, parents)',
'supportsAllDrives' => 'true',
'q' => "mimeType = 'application/vnd.google-apps.folder'"
);
$results = $service->files->listFiles($optParams);
foreach ($results as $file) {
echo $file['name'];
echo "<br>";
}
Upvotes: 0
Views: 252
Reputation: 1057
I notice that the sample code only shows query parameters using the files.list. In order to gather the Shared drives of the organization you would need
drive.list
You can also test it yourself to give you an idea from their official documentation. Make sure to select "true" as a Super Admin so you can get all the Shared drives from the domain.
The closest available documentation I was able to find with references to Shared Drives can be found here. You might find dificult to search for example codes or data for it, this could be because the original name was "Team Drives". Which could explain the lack of available documentation for PHP samples with the name "Shared Drives".
Based on that I was able to find some useful references that could help you. "List shared drives from Google Drive"
$service->teamdrives->listTeamdrives()->getTeamDrives();
This sample code was found over this thread. It might be old, however all the API calls for Shared Drives in V3 use the term "teamDrives".
I would like some clarification to the second question: Help me get the email of the user.
Upvotes: 1