I am working on google docs API and google drive API. I am facing one issue while setting the permissions for editors/writers for not able to share the google docs to anyone except for the owner using google docs API.
Can anyone tell me how we can set or change the permissions so that no one can share the google docs to anyone except the owner.I went through this links https://developers.google.com/apps-script/reference/drive/file#isShareableByEditors() and found one function isShareableByEditors() and https://developers.google.com/drive/api/v3/reference/files in this link I found one more function writersCanShare(). But I am not able to understand How I put this function or set the functions to get my work done.
I want to do it with google API only with PHP language. Any help would be much appreciated.
CodePudding user response:
I believe your goal is as follows.
- You want to make users not share the Google Document, while the user can edit the Google Document.
- You want to achieve this using googleapis for PHP.
I think that in this case, writersCanShare
is required to be false
. I think that your direction is correct. So, in order to achieve your goal, how about the following sample script?
Sample script:
This script uses Drive API v3.
$service = new Google_Service_Drive($client); // Please use your authorization script.
$fileId = "###"; // Please set the file ID.
$metadata = new \Google_Service_Drive_DriveFile([
"writersCanShare" => false,
]);
$res = $service->files->update($fileId, $metadata);
If an error related to the scope occurs, please include the scope of
https://www.googleapis.com/auth/drive.metadata
and/orhttps://www.googleapis.com/auth/drive
and please authorize the scopes again. But, if you are required to usehttps://www.googleapis.com/auth/drive.file
, I think that you can use it.When this script is run, the user who is not the owner of Document cannot share the document while the user can edit the document.