ujjal
ujjal

Reputation: 235

How to shared file in Google Drive API v3 in php?

How to share file in Google Drive API v3?I have listed of file and I want to add share functionality with Laravel?

Upvotes: 1

Views: 4087

Answers (1)

Saad Zaamout
Saad Zaamout

Reputation: 676

If you mean sharing a file with another user, then you can do the following

client = new Google_Client();
// setup the client the way you do
// ....

service = new Google_Service_Drive(client)
$role = 'writer';
$userEmail = '[email protected]';
$fileId = 'The ID of the file to be shared';

$userPermission = new Google_Service_Drive_Permission(array(
  'type' => 'user',
  'role' => $role,
  'emailAddress' => $userEmail
));

$request = $service->permissions->create(
  $fileId, $userPermission, array('fields' => 'id')
);

Reference:

https://developers.google.com/drive/v3/web/manage-sharing

Check my git repo for more useful examples https://github.com/sazaamout/gDrive/blob/master/gDrive.php

Upvotes: 8

Related Questions