Answer the question
In order to leave comments, you need to log in
How to disable access to a file by link using the Google Drive API?
There is a need to change access to files on Google Drive using the Google Drive API.
I can not find a clear explanation of how to switch file access.
The task is to disable access by link in general, so that files are accessible only by e-mail from the list of poked around.
If you request permissions for a file that does not have access by link, then the following parameters are returned:
Permission:[
{"deleted":false,
"displayName" :"user name",
"emailAddress":"[email protected]",
"id":"111111111111111",
"kind":"drive#permission",
"photoLink":"photoLink.jpg",
"role": "owner",
"type":"
Permission:[
{"allowFileDiscovery":true,
"id":"anyone",
"kind":"drive#permission",
"role":"reader",
"type":"anyone"},
{"deleted": false,
"displayName":"user name",
"emailAddress":"[email protected]",
"id":"111111111111111",
"kind":"drive#permission","photoLink":"photoLink.jpg" ,
"role":"owner",
"type":"user"}
]
The presence of access by reference not only changes the value of one of the existing attributes, but generally adds a separate piece
{"allowFileDiscovery":true,
"id":"anyone",
"kind":"drive#permission",
"role":"reader",
"type":"anyone"}
Answer the question
In order to leave comments, you need to log in
In general, I misjudged access to a file by reference a little - I thought that it should be one parameter, but in fact it is a separate independent permission.
As a result, I solved the problem with access - using the
permissions().delete(fileId, permissionId).execute();
Which takes 2 parameters as input:
* file/folder
id * permish id
In fact - added a loop - checking if the perm id contains a piece of anyone
if (permission.getId().contains("anyone")){
}
If the condition is met, then 2 required parameters are passed to the delete method and are deleted.
The presence of a piece "anyone" is checked - because access to everyone on the Internet is "anyone", and access to everyone who has a link is "anyoneWithLink".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question