3

Is there any way to download publically shared file from Google Drive using REST API in Android? the official documentation page here says to do

GET https://www.googleapis.com/drive/v3/files/0B9jNhSvVjoIVM3dKcGRKRmVIOVU?alt=media
Authorization: Bearer <ACCESS_TOKEN>

Where actually can I get the ACCESS_TOKEN? I authenticated my account by following the quick start guide here and generated credentials.xml file

I want to download a shared file in my app, which i think would not require user authentication, if there is any way to do this without asking user for sign-in using GoogleSingInOption.Builder let me know by answering this question

i have checked similar questions like this, but they all show solution for downloading or uploading files from users personal drive space by authenticating user

Jon
  • 3,573
  • 2
  • 17
  • 24
imin
  • 4,504
  • 13
  • 56
  • 103
  • See my answer here: https://stackoverflow.com/questions/12164024/android-open-and-save-files-to-from-google-drive-sdk/54394625 – live-love Jan 28 '19 at 01:59

1 Answers1

0

If you just scrolled down a bit on that page, you'd see that if you authenticate with google you can just use their api to make the request for you.

String fileId = "0B9jNhSvVjoIVM3dKcGRKRmVIOVU";
OutputStream outputStream = new ByteArrayOutputStream();
driveService.files().get(fileId)
    .executeMediaAndDownloadTo(outputStream);
David
  • 1,636
  • 19
  • 27
  • I wanted to try that, but what's driveService? – imin Apr 14 '18 at 17:26
  • I think that is referring to this class https://developers.google.com/resources/api-libraries/documentation/drive/v3/csharp/latest/classGoogle_1_1Apis_1_1Drive_1_1v3_1_1DriveService.html – David Apr 14 '18 at 17:28
  • I was wrong, in the quickstart guide the function getDriveService() is created and ran, i tkink driveService is referring to that object (class com.google.api.services.drive.Drive) – David Apr 14 '18 at 17:31
  • Hmm... so do you have any idea on how to get it done? – imin Apr 14 '18 at 17:45
  • Drive driveService = getDriveService(); – David Apr 14 '18 at 17:47
  • i think this answers your question better https://stackoverflow.com/questions/12164024/android-open-and-save-files-to-from-google-drive-sdk – David Apr 14 '18 at 17:49