Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the direct download link of a file by google drive api v3 in java

How to get the direct download link of a file by google drive api v3 in java ?

Hi all, I've worked with Google Drive Api in Android for a week, I used both Android Drive SDK and Drive Rest Api for java but I can't find the way how to how to get the direct download link of a file (anyone can read) on Drive. I've try How to get the url of a file of google drive to download in android but it's not work. Please help me. Thanks.

like image 943
Hưng Avatar asked Dec 15 '22 08:12

Hưng


2 Answers

Given that you have the actual FILE-ID for the file , you can download it using the download link

drive.google.com/uc?id=FILE-ID&export=download

like image 169
Michael Nyamande Avatar answered May 02 '23 07:05

Michael Nyamande


If you want to have the direct download link of a file, DriveFile doesn't seem to be what you're looking for. What you can do is to use the Drive API web service instead. Note that you're still required to be authenticated for you to use the API.

Check out the Download Files section of the documentation, there are 3 ways for you to download the file.

  • Download a file — files.get with alt=media file resource
  • Download and export a Google Doc — files.export
  • Link a user to a file — webContentLink from the file resource

Another alternative is for you to use the webContentLink for you to download the file. However, this is only available for files with binary content in Drive.

like image 43
adjuremods Avatar answered May 02 '23 07:05

adjuremods