我正在使用 google Drive php api 来更改文件的权限。当我将“角色”设置为“作家”时,它会起作用,但是当我将“角色”设置为“所有者”时,它会起作用,如下所示:
$batch = $driveService->createBatch();
$userPermission = new Google_Service_Drive_Permission(array(
'type' => 'user',
'role' => 'owner',
'transferOwnership' => 'true',
'emailAddress' => 'c*****@c*******.org'
));
$request = $driveService->permissions->create(
$fileId, $userPermission, array('fields' => 'id'));
$batch->add($request, 'user2');
$results = $batch->execute();
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息,指出“transferOwnership”必须设置为 true。但是,好像我已经将transferOwnership 设置为true!我究竟做错了什么?
exception 'Google_Service_Exception' with message '{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "The transferOwnership parameter must be enabled when the permission role is 'owner'.",
"locationType": "parameter",
"location": "transferOwnership"
}
],
"code": 403,
"message": "The transferOwnership parameter must be enabled when the permission role is 'owner'."
}
Run Code Online (Sandbox Code Playgroud)
transferOwnership应设置为查询参数,而不是在请求正文中。
例子:
$batch = $driveService->createBatch();
$userPermission = new Google_Service_Drive_Permission(array(
'type' => 'user',
'role' => 'owner',
'emailAddress' => 'c*****@c*******.org'
));
$request = $driveService->permissions->create(
$fileId,
$userPermission,
array('fields' => 'id', 'transferOwnership' => 'true'));
$batch->add($request, 'user2');
$results = $batch->execute();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5750 次 |
| 最近记录: |