我正在使用适用于php的Google Drive API,并尝试将文件复制到特定的文件夹并为其授予权限。
当我尝试使用调试器毫无问题地执行它时,权限将设置为正确的用户。但是,当我尝试“正常”执行它时,结果将永远不会相同,并且设置权限时似乎会崩溃(或超时)。
这是我的代码:
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
));
}
}
这是函数调用:
changeFileRights($fileId, ['reader', 'writer'], ['email1@gmail.com', 'email2@gmail.com']);
答案 0 :(得分:0)
好的,我设法通过增加php.ini的最大执行限制来做到这一点。执行时间太长,这就是为什么每次都不能给我相同的结果。