I’m building an application that uses Google Drive. My goal is to let users share files by creating a link. I want to set the permissions to ‘anyone’ and ‘withLink’.
Here’s my problem: I can’t figure out how to get the shareable link through the API. When I share a file manually in Google Drive, I see a link like this:
https://docs.google.com/presentation/d/SOME-ID/edit?usp=sharing
But I can’t find this link in the file resource object or in the response when I set permissions through the API. Does anyone know how to get this shareable link using the Google Drive API?
I’ve looked at the API docs but couldn’t find a clear answer. Any help would be great!
hey mate, i’ve got a trick for ya. after settin the permissions, you can make the link yourself. it’s like this:
https://drive.google.com/file/d/{FILE_ID}/view?usp=sharing
just swap {FILE_ID} with your actual file ID. works like a charm for most stuff. give it a go!
I’ve dealt with this exact issue in a project recently. The shareable link isn’t directly provided by the API, but you can construct it yourself using the file ID. After setting the permissions, you can create the link like this:
https://drive.google.com/file/d/{FILE_ID}/view?usp=sharing
Replace {FILE_ID} with the actual ID of the file. This works for most file types. For Google Docs, Sheets, or Slides, you’ll need to use a slightly different format:
https://docs.google.com/{TYPE}/d/{FILE_ID}/edit?usp=sharing
Where {TYPE} is ‘document’, ‘spreadsheet’, or ‘presentation’ respectively.
Hope this helps solve your problem!
I’ve been working with the Google Drive API for a while now, and I can confirm that getting the shareable link isn’t straightforward. However, there’s a workaround that’s been reliable for me.
Instead of looking for the link in the API response, you can construct it yourself using the file ID. Once you’ve set the permissions to ‘anyone’ and ‘withLink’, use this format:
https://drive.google.com/file/d/{FILE_ID}/view?usp=sharing
Replace {FILE_ID} with your file’s ID, and you’re good to go. This method has worked consistently for me across various file types.
One thing to note: if you’re dealing with Google Docs, Sheets, or Slides, you’ll need to adjust the URL slightly. For these, use:
https://docs.google.com/{TYPE}/d/{FILE_ID}/edit?usp=sharing
Where {TYPE} is ‘document’, ‘spreadsheet’, or ‘presentation’ depending on the file type.
This approach has saved me a lot of headaches in my projects. Give it a try and see if it solves your issue.