2
votes

I'm using the google drive php api to change permissions of a file. It works when I set the "role" to "writer", but when I set the "role" to "owner", as such:

$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();

I get an error that "transferOwnership" must be set to true. But, it seems like I have already set transferOwnership to true! What am I doing wrong?

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'."
 }
1

1 Answers

5
votes

transferOwnership should be set as a query parameter and not in the body of the request.

Example:

$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();