Skip to content

Instantly share code, notes, and snippets.

@creativedrewy
Last active August 12, 2021 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creativedrewy/6b4cfcccc30e82e2867e253f50d6108e to your computer and use it in GitHub Desktop.
Save creativedrewy/6b4cfcccc30e82e2867e253f50d6108e to your computer and use it in GitHub Desktop.
## Quick Hit: Getting valid thumbnails using Google Drive Library on Android

Update 10-28-2016: Update to the discussion of the request fields.

The Problem:

When using the Google Drive Java Client Library to list a user's photos and videos in your app, the thumbnailLink property is empty.

The Solution:

As far as I can tell, there is literally no good documentation on the solution for this. However, with the help of a co-worker and the REST API operations, I've gotten the solution.

To get valid thumbnailLink values, you have to make sure you specify the thumbnail field in your request. Since you're doing a custom field request you have to be sure to add the other fields you want as well:

Drive.Files.List request = googlDriveService.files() 
                    .list()
                    .setFields("files/thumbnailLink, files/name, files/mimeType, files/id")
                    .setQ("Your file param and/or mime query");

FileList files = request.execute();
files.getFiles();  //Each File in the collection will have a valid thumbnailLink value

A sample query might be:

"mimeType = 'image/jpeg' or mimeType = 'video/mp4'"

Hope this helps!

PS

Note that there is a difference between the Google Drive API for Android and the Google Drive Java Client Library. The latter library allows you to do more advanced things, like actually get all the files for a given account, not just those created by your app. The following link has a really good guide on getting started with it:

https://developers.google.com/drive/v3/web/quickstart/android

Oddly, I can't get the file query to work as it is on that quick start. But using my above query works great, so perhaps start with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment