如何在php中的Google Drive API v3中共享文件?

时间:2018-02-01 13:44:35

标签: google-drive-api

如何在Google Drive API v3中共享文件?我列出了文件,我想在Laravel中添加共享功能?

1 个答案:

答案 0 :(得分:2)

如果您的意思是与其他用户共享文件,则可以执行以下操作

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

service = new Google_Service_Drive(client)
$role = 'writer';
$userEmail = 'user@gmail.com';
$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')
);

参考:

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

检查我的git repo以获取更多有用的示例 https://github.com/sazaamout/gDrive/blob/master/gDrive.php