Search code examples
google-drive-apifile-sharinglinkshare

Create new Permission for file Uploaded through Google Drive API


My application is uploading file to GoogleDrive and then my application opens file for editing into GoogleDocs. Users of my application are using Google apps and from their admin console they have set the link sharing default value to "On - Anyone at theirdomain.com". Now when they use my application and it uploads the file, I am not able to set the Link sharing setting to "On - Anyone at theirdomain.com with link".

Can someone provide me the pointer/sample code how to set the link sharing option using Google drive API for uploaded file so that my application can open file into editor for collaboration.


Solution

  • This should help resolve your issue. I executed the following steps and was able to successfully set the Link Sharing settings to anyone with link.

    1. Use Permission.Delete to remove the 'domain' permission of the file.
    2. Use Permission.Insert to re-insert the permission for the 'domain' with setting the withLink option to true.
    3. Now, verify the link sharing settings is reflected with the change.

    You can always reference to the Google public documentation about Sharing files in Drive API. Also refer to the full Google Documentation for Drive.Permission.

    Hope this helps and Good Luck!