i'm in a company for weeks, with the idea to developp php intranet (as a website), using google api to manage some google sheet in google drive.
step by step :
-the user connect to the application with gmail adresse to access to the website. so i used google oauth 2.0 and openid for the security aspect, just for connection and verification(the application verify if the email is correct and have a specific domain : user@test.fr and not user@test123.fr)
-the application need after that to display and manage some directories and google spreadsheet files in google drive on a specific another gmail adresse (ex: service@test.fr)
i've already done the connection to my php application, and i've success to modify a simple spreadsheet test using service account.
edit : so i used service account following this link : https://github.com/googleapis/google-api-php-client/blob/master/docs/oauth-server.md#delegating-domain-wide-authority-to-the-service-account
i wrote this following code to just show the files i have in the service@test.fr google drive :
<?php
require __DIR__ .'/vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=intranetCredentials.json');
$client = new Google_Client([
'timeout' => 2.0,
'verify' => __DIR__ . '/cacert.pem'
]);
$client->useApplicationDefaultCredentials();
$client->setScopes(Google_Service_Drive::DRIVE);
$driveManager = new Google_Service_Drive($client);
// Print the names and IDs for up to 10 files.
$optParams = array(
'pageSize' => 1,
'fields' => 'nextPageToken, files(id, name)'
);
$results = $driveManager->files->listFiles($optParams);
if (count($results->getFiles()) == 0) {
print "No files found.\n";
} else {
print "Files:\n";
foreach ($results->getFiles() as $file) {
printf("%s (%s)\n", $file->getName(), $file->getId());
}
}
i think i'm on the way, but when i execute my php app, i'm getting : "no files found" whereas i have google sheet and google doc file
i've done everything following the link except the delegating domain wide authority to the service account.
any ideas ?