I'm using the Google Drive api for php and trying to copy files to a specific folder and give them permissions.
When i try to execute it with debugger on no problem, the rights are set to the good users. But when i try to execute it "normally" the results are never the same and it seems to crash (or timeout) when setting the rights.
This my code :
function deleteFilePermissions($fileId)
{
global $driveService;
$results = $driveService->permissions->listPermissions($fileId, array(
'fields' => 'nextPageToken, permissions(id, role, emailAddress)'
));
foreach ($results->getPermissions() as $permission) {
if ($permission->getRole() != 'owner'
&& $permission->getEmailAddress() != 'noreply@opportunities-fo-1541429464609.iam.gserviceaccount.com')
$driveService->permissions->delete($fileId, $permission->getId());
}
}
function changeFileRights($fileId, $rights, $emailAddresses)
{
global $driveService;
deleteFilePermissions($fileId);
foreach ($rights as $key => $right) {
$userPermission = new Google_Service_Drive_Permission(array(
'type' => 'user',
'role' => $right,
'emailAddress' => $emailAddresses[$key]
));
$request = $driveService->permissions->create($fileId, $userPermission, array(
'fields' => 'id',
'sendNotificationEmail' => false
));
}
}
This is the function call:
changeFileRights($fileId, ['reader', 'writer'], ['email1@gmail.com', 'email2@gmail.com']);