I have problem with google drive api v3. I took google example and I tried. I could read folder content but I did nothing with folder permission.
I received error 403, "Insufficient Permission". I can't create or read all permissions for the folder.
<?php
require_once __DIR__.'/vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfig('client_secrets.json');
$client->addScope(Google_Service_Drive::DRIVE);
$client->setAccessType('offline');
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
$drive = new Google_Service_Drive($client);
$folderId = '1_ip3-WUs4F6atNdElJ3KHccAV4lI0nLL';
$optParams = array(
'pageSize' => 100,
'fields' => "nextPageToken, files(id,name)",
'q' => "'".$folderId."' in parents"
);
$results = $drive->files->listFiles($optParams);
if (count($results->getFiles()) != 0) {
foreach ($results->getFiles() as $file) {
echo "Id: " . $file->getId() . " Name: " . $file->getName() . "<br>";
}
}
} else {
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
//+!+!+!+!+!+!+!+!+!+! Next code doesn't WORK !+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!//
$fileId = '1UXSg5W-XIX82izGK8uEXXWPUCLcDGRa1';
$userPermission = new Google_Service_Drive_Permission(array(
'type' => 'user',
'role' => 'reader',
'emailAddress' => '[email protected]'
));
$request = $drive->permissions->create($fileId, $userPermission, array('fields' => 'id'));
echo $request;
?>