(400)使用google-api-php-client库时的错误请求

时间:2013-03-11 15:57:16

标签: php google-drive-api google-api-php-client

上传文件并立即执行权限 - >更新:

public function  sharingFile() {
    $fileId = $this->file['id'];
    $permissionId = $this->file['userPermission']['id'];
    try {
        $permission = $this->service->permissions->get($fileId, $permissionId);
        $permission->setRole('writer');
        $permission->setType('default');
        print_r($permission);
        return $this->service->permissions->update($fileId, $permissionId, $permission);
    } catch (Exception $e) {
        return "Error: " . $e;
    }
    return NULL;
}

并收到错误:

Error: exception 'Google_ServiceException' with message 'Error calling PUT
https://www.googleapis.com/drive/v2/files/0B6xE_F1PfpXTbF9IdHgxbEJueEk/permissions/me:
(400) Bad Request' in Z:\home\site.com\www\google-api-php-client\src\io\Google_REST.php:66
Stack trace:
#0 Z:\home\site.com\www\google-api-php-client\src\io\Google_REST.php(36):  Google_REST::decodeHttpResponse(Object(Google_HttpRequest))
#1 Z:\home\site.com\www\google-api-php-client\src\service\Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest))
#2 Z:\home\site.com\www\google-api-php-client\src\contrib\Google_DriveService.php(774): Google_ServiceResource->__call('update', Array)

它可能是图书馆中的一个错误?
求助。

1 个答案:

答案 0 :(得分:0)

您的代码正在尝试更新文档所有者的权限,并使该用户成为编写者。 Drive文档必须只有一个所有者,因此您的请求无效。