Google Drive API - 将所有权转让为委派管理员

时间:2016-05-27 08:58:29

标签: google-api google-drive-api

我正在尝试将所有权从普通用户转移到具有Drive服务权限和数据传输权限的委派管理员用户,这是documentation所必需的。

我试图代表委派的管理员用户执行此操作。 原因是,我想确保由我们域中的任何用户创建的每个文件都将其所有权转移给一个管理员用户。

所以我有一个(离线)访问令牌和刷新令牌存储在我的后端。我使用Google Drive API中的推送通知服务,使用此(已删除的)代码响应我的域中用户创建的新文件:

$client = new \Google_Client();
$client->setAuthConfigFile('client_config.json');

// This is the access token json for the delegated admin user.
$client->setAccessToken('{access_token_json_string}');

$drive = new \Google_Service_Drive($client);

// This is the file created by the user. It has two permissions: The user is the 'owner' and the admin user is the 'writer'
$fileId = 'XXX_XXxXXXXxxXXXxxX';

// this is the admin user's permission id, of role 'writer'. This is the one I am trying to change to 'owner'.
$permissionId = '1234567890';

// I've tried setting all values, but that doesn't help
$permission = new \Google_Service_Drive_Permission();
$permission->setId($permissionId); 
$permission->setEmailAddress('admin@domain.com');
$permission->setValue('admin@domain.com');
$permission->setType('user');
$permission->setRole('owner');

// Both 'put' and 'update' raise the same error
$drive->permissions->update($fileId, $permission->getId(), $permission, array(
    'transferOwnership' => true
));

我得到的回应:

Error calling PUT https://www.googleapis.com/drive/v2/files/XXX_XXxXXXXxxXXXxxX/permissions/1234567890?transferOwnership=true: (403) Insufficient permissions for this file

请注意,所有其他API调用都能正常工作,因此访问令牌有效。 Google云端硬盘内部也没有可用的选项来转移所有权(作为管理员用户)。将其从普通用户转移到管理员用户可以按预期工作。

0 个答案:

没有答案
相关问题