Search code examples
phpgoogle-apigoogle-drive-apigoogle-api-php-client

How to set capabilities for a file while sharing with someone using Google drive API V3?


I want to set capabilities like canDownload = false, canCopy = false while sharing a Google drive file with someone using Google API V3.

Right now I'm setting multiple permissions for that file and permissions are working fine but capabilities are not setting.

Here is the code for setting permissions and capabilities :

putenv('GOOGLE_APPLICATION_CREDENTIALS=client_secret.json');
     $client = new Google_Client();
     $client->setApplicationName('xyz');
     $client->setAccessType("offline");    
     $client->useApplicationDefaultCredentials();
     $client->setSubject('abc@xyz.com');
     $client->setScopes(array('https://www.googleapis.com/auth/drive.file','https://www.googleapis.com/auth/drive'));
     $service = new Google_Service_Drive($client);
     $optParams = array('sendNotificationEmail'=> false);
     $capabilities = array('canDownload' => false, 'canCopy' => false );

     $permissiondata =insertPermissionview($service,$request['file_google_id'],$optParams, $capabilities, $request['email_id'],'user','reader');

     $newPermissiondata = new Google_Service_Drive_Permission();
     $newPermissiondata->setExpirationTime($request['permission_expires_on'].'T10:00:00-05:30');
     $newPermissiondata->setRole('reader');
     $permissiondatavalue=$service->permissions->update($request['file_google_id'],$permissiondata['id'],$newPermissiondata);

Reference : https://developers.google.com/drive/api/v3/reference/files

So, basically my question is how can I disable download, copy, print option for a reader with whom I've shared my google drive file using drive API?


Solution

  • If you check the documentation for a fileresource You will notice that neither of those fields are writable. So doing a file.update and setting those fields is going to have no effect. I dont think you can set them when the file is created either as it would make sense that you can download and copy it if you are creating it. These fields are more then likely for googles internal use.

    enter image description here

    enter image description here

    a permission resource just lets you set if the user has access to the file not what they can do with it.