Google Drive direct download link creation for shared files

When sharing files on Google Drive the link provided isn’t a direct link to download the file. Instead, it’s link to a view page for the file where you are then provided with the option of downloading the file. This isn’t great if you’re using the command line.

Google Drive File ID

After digging around the Google Drive API documentation, I came across their API Explorer which let me run a GET request using my file’s ID which was the string of characters that were part of the original sharing link. This can be used to create a Google Drive direct download link.

The API Explorer returned a JSON object containing detailed information about my file.

Google Drive Direct Download Link

The downloadUrl could be helpful but it would clearly be a hassle for my purposes and the resource documentation states the URL is short lived. What I really want to use for direct downloads is the webContentLink.

https://docs.google.com/uc?id={FileID}&export=download

You can switch docs for drive and &export=download doesn’t appear to be necessary.

https://drive.google.com/uc?id={FileID}

Testing Direct Download Link

Since the visibility for my file is set to Anyone with the link, I can easily download the file using cURL without having to worry about authentication(Public on the web works as well).