Use Google Drive API to change link sharing permis

2020-04-19 05:40发布

Is there a way to programmatically change the link sharing permissions for a file? I'm administering a Google Apps for Work account and I want to have a policy for every file in a folder named "Confidential" to have a certain set of permissions for Link Sharing, "Prevent editors from changing access and adding new people", and "Disable options to download, print, and copy for commenters and viewers".

It doesn't look like there's a way to do this in the Google Admin console, but is there a way for me to write a script that goes through periodically and "fix" every file's permissions?

2条回答
Explosion°爆炸
2楼-- · 2020-04-19 06:24

First of all Google Drive File's uniqueness is in their ID which is given by Google when you upload, not in the filename like the desktop OS.

If you make sure that there is only one "Confidential" file, then you can list files from folder. Later , you can modify "File" properties by :

  1. To "Prevent editors from changing access and adding new people" :

    new File().setWritersCanShare(Boolean value)

  2. To "Disable options to download, print, and copy for commenters and viewers":

    new Labels().setRestricted(Boolean value)

Note that label can only be applied to files not folder. This is using Java, so you can can have a cron to accomplish this task.

查看更多
不美不萌又怎样
3楼-- · 2020-04-19 06:43

With the latest version of Google Drive V3, you need to do the following to "Disable options to download, print, and copy for commenters and viewers":

file.setViewersCanCopyContent(false);
查看更多
登录 后发表回答