V
V
Vladislav Tsepish2018-11-07 21:16:08
Java
Vladislav Tsepish, 2018-11-07 21:16:08

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

2 answer(s)
V
Vladislav Tsepish, 2018-11-12
@VladislavTsepish

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".

A
alfss, 2018-11-07
@alfss

https://developers.google.com/drive/api/v3/referen...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question