0

I have managed to understand the way to authorize an app's access to a user's protected information using the OAuth 2.0 credentials. Yet my app requires to download a bunch of PDF files from a third party's Drive (not my users' ones). The folder is public so there should be no problem with the authorization.

How could I achieve that? What piece of code and what libraries do I need in Java? Thank you!

Ionna
  • 223
  • 4
  • 19

1 Answers1

0

You'll be using MediaHttpDownloader and MediaHttpDownloaderProgressListener as mentioned here:

class CustomProgressListener implements MediaHttpDownloaderProgressListener {
public void progressChanged(MediaHttpDownloader downloader) {

   switch (downloader.getDownloadState()) {
      case MEDIA_IN_PROGRESS:
         System.out.println(downloader.getProgress()); 
         break;
      case MEDIA_COMPLETE:
         System.out.println("Download is complete!");
   }
  }
 }

    OutputStream out = new FileOutputStream("/tmp/driveFile.jpg");

   DriveFiles.Get request = drive.files().get(fileId);
   request.getMediaHttpDownloader().setProgressListener(new           CustomProgressListener());
   request.executeMediaAndDownloadTo(out);

You can also try to use the sample in this thread. Dont forget the official Google Android samples.

Community
  • 1
  • 1
ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56