Mic*_*ele 3 php google-drive-api google-oauth service-accounts google-cloud-platform
我使用服务帐户将文件上传到谷歌云端硬盘中的共享文件夹。
一段时间后,我发现服务帐户拥有的文件消耗了服务帐户的驱动器存储(我的错),现在我已经用完了服务帐户的驱动器空间。
我已经将域范围的权限委托给服务帐户,因此新文件将归我所有并使用我的个人存储配额。
这样做:将域范围的权限委派给服务帐户
以及如何通过 google/apiclient 从 PHP 使用 Google Drive API 的 API 密钥
为了避免将来出现错误和混乱,我想更改旧文件的所有者。我不断收到此错误:
Run Code Online (Sandbox Code Playgroud){ "error": { "code": 400, "message": "Bad Request. User message: \"You can't change the owner of this item.\"", "errors": [ { "message": "Bad Request. User message: \"You can't change the owner of this item.\"", "domain": "global", "reason": "invalidSharingRequest" } ] } }
这是我使用 PHP 客户端的代码
$client = new Google_Client();
$client->setApplicationName('My Name');
$client->setScopes(Google_Service_Drive::DRIVE);
$client->setAuthConfig($my_credentials);
$client->setAccessType('offline');
//$client->setSubject('my_personal_account');
$service = new Google_Service_Drive($client);
$newPermission = new Google_Service_Drive_Permission();
$newPermission->setEmailAddress('my_personal_account');
$newPermission->setType('user');
$newPermission->setRole('owner');
$service->permissions->create(
$fileId,
$newPermission,
array("fields" => "id", "transferOwnership" => true)
);
Run Code Online (Sandbox Code Playgroud)
无论客户端中是否有 setSubject,我都会遇到相同的错误。我尝试过使用
$newPermission->setRole('writer');
$newPermission->setPendingOwner(true);
Run Code Online (Sandbox Code Playgroud)
但没有成功。
文件所有权的转移只能在同一域的帐户之间进行。发生错误的原因是服务帐户和您的帐户不属于同一域。
如果您有权访问共享云端硬盘并且能够添加具有添加文件权限的用户,请添加服务帐户并将文件移动到共享云端硬盘。
有关的
其他相关
归档时间: |
|
查看次数: |
1502 次 |
最近记录: |