Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Drive API downloadUrl does not work

  • I have some audio recordings on Google Drive
  • the files are "viewable by anyone with the link"
  • I have created a podcast feed that links to these files

In order for a podcast client to download the files, it needs a direct download link. The Google Drive API returns two fields in a file's metadata that can play this role:

  • webContentLink is intended to be used in a browser. It allows my podcast client to download files less than 25MB; unfortunately, over this amount Google requires user confirmation since the file is not virus-scanned. This user-confirmation step prevents my podcast clients from downloading the file if it is over 25MB.
  • downloadUrl is what you're supposed to use, but I cannot get it to work at all. If I copy-paste a downloadUrl directly into my browser's address bar, I get nothing. Similarly my podcast client can't download anything with a downloadUrl.

This issue seems unresolved and suggests this is still broken, but I have a few questions:

  • should I need to submit an API key with the downloadUrl request? No key is needed for webContentLink.
  • is there a workaround for this issue?
like image 952
Sean Mackesey Avatar asked Nov 09 '22 19:11

Sean Mackesey


1 Answers

When requesting the file with the downloadUrl you must specify the following authorization in your request header:

"Authorization: Bearer $token"

Where $token is the access_token returned by gapi for the user like this:

gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse().access_token;

So if you were using curl the request would be something like this:

curl -o download -H "Authorization: Bearer $token" $downloadUrl 
like image 114
supersan Avatar answered Jan 04 '23 02:01

supersan