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

ujj*_*jal 1 google-drive-api

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

Saa*_*out 7

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

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')
);
Run Code Online (Sandbox Code Playgroud)

参考:

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

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