Accessing public Google Drive files without authorization

I’m working on a Java desktop app that needs to grab public files from Google Drive. I thought I could use the webContentLink to download files without user login, but it’s not that simple.

Here’s what I’ve tried:

String fileLink = myFile.getDownloadUrl();
InputStream fileStream = new URL(fileLink).openConnection().getInputStream();

This works fine for small files. But when I try to download bigger files, Google throws up a virus scan warning. The user has to click through this, which breaks my app’s flow.

Is there a way to bypass this and download public files directly? I’m stumped and could really use some help. Thanks!

hey mikechen, i’ve had this problem too. what worked for me was using the google drive api v3. you can use the files.get method with alt=media parameter to download files directly. it’s a bit more work to set up, but it avoids that annoying virus scan popup. give it a shot and let us know how it goes!

I’ve encountered this issue before, and there’s a potential solution that might work for you. Instead of using the webContentLink, try utilizing the exportLinks property of the file metadata. This approach often bypasses the virus scan warning for larger files.

Here’s a basic example of how you could implement this:

Drive.Files.Get request = drive.files().get(fileId);
File file = request.execute();
String exportUrl = file.getExportLinks().get("application/pdf");

if (exportUrl != null) {
    InputStream is = drive.getRequestFactory().buildGetRequest(new GenericUrl(exportUrl)).execute().getContent();
    // Process the input stream as needed
}

This method has worked reliably for me in several projects. Just ensure you have the necessary Google Drive API setup and dependencies in place. Also, be aware that not all file types support export, so you may need to handle different scenarios accordingly.

I’ve faced a similar issue in one of my projects. The virus scan warning is a Google Drive feature that can’t be easily bypassed, especially for larger files. However, I found a workaround using the Google Drive API directly.

Instead of relying on the webContentLink, you can use the files.get method with the ‘alt=media’ parameter. This approach allows you to download the file content directly without triggering the virus scan warning.

Here’s a rough outline of how you can implement this:

  1. Set up Google Drive API credentials for your app
  2. Use the Drive service to get the file metadata
  3. Use the files.get method with ‘alt=media’ to download the file

This method worked well for me, even with larger files. It does require a bit more setup, but it provides a smoother user experience in the long run. Just remember to handle potential API quota limits and error responses in your code.