假设我有一个需要在后台服务中访问Drive文件的Web应用程序.它将拥有自己正在访问的文件,或者在所有者共享文档的Google帐户中运行.
我知道我的应用程序需要一个刷新令牌,但我不想编写代码来获取它,因为我只会做一次.
NB.这不是使用服务帐户.该应用将在传统的Google帐户下运行.在某些情况下,服务帐户是一种有效的方法.但是,使用Oauth Playground模拟应用程序的技术可以节省大量的冗余工作,并适用于不支持与服务帐户共享的任何API.
我使用服务帐户将文件上传到谷歌云端硬盘中的共享文件夹。
一段时间后,我发现服务帐户拥有的文件消耗了服务帐户的驱动器存储(我的错),现在我已经用完了服务帐户的驱动器空间。
我已经将域范围的权限委托给服务帐户,因此新文件将归我所有并使用我的个人存储配额。
这样做:将域范围的权限委派给服务帐户
以及如何通过 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 …Run Code Online (Sandbox Code Playgroud) php google-drive-api google-oauth service-accounts google-cloud-platform