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>";
}
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"
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.