Tony's answer is correct, and here is an addon to his instructions if someone else wants to check it out. Please note that I did not write code for this due to time limits, but I tested it using the Google APIs provided on the Google Drive Google webpage. I checked this by doing the following:
Go to the insert permission page here - Tony was right, you are not deleting the existing permission, but instead you are adding permission to this: https://developers.google.com/drive/v2/reference/permissions/insert
In the API browser, enter "role" as "reader" and "type" as "someone."
Go to your drive: https://drive.google.com/drive/#my-drive and you will see that the file is now open - if you hover over the green link icon in the screenshot below, it will tell you that now he is divided.
You can also copy the link for the document and paste it into incognito mode in Chrome to check if you can access the version of the document for reading in incognito mode, and it should work.
Additionally:
The code should not be too complicated, here it is:
Permission newPermission = new Permission(); newPermission.setType("anyone"); newPermission.setRole("reader"); try { return service.permissions().insert(fileId, newPermission).execute(); } catch (IOException e) { System.out.println("An error occurred: " + e); }
Simon source share