0

I have questions regarding the behavior of the Google Drive v3 API files resource thumbnailLink property for Google Docs files. There are two different types of thumbnail links created depending if the file is a Google Doc or other type of file. When going to the thumbnailLink URL for a Google Doc I always get a 404 response, unless I open it on a Chrome browser where I am logged in with the same Google account.

My questions about the thumbnail link are:

  • What is the minimum OAuth scope required to access it?
  • What are the exact criteria required for me to have see the thumbnail image in a browser instead of getting a 404?
  • Is it possible to make the link to google doc thumbnails publicly accessible?
    • If not, is there some alternative way to build the thumbnail url?

I preferably want to avoid this answer as it will either expose the access key or add complication by setting up a proxy.

This is the format of the google doc thumbnail link: https://docs.google.com/feeds/vt?gd=true&id=1TjchRkZ0MxurnBkKNitDtoMQiyJUV6rv0z9HQ7kHEg0&v=3&s=AMedNnoAAAAAXaTCgqfi_sjlT4SAGAEd_ZABNBoSvMnM&sz=s220

Other types of documents that use the following type of thumbnail link are publicly available: https://lh3.googleusercontent.com/JkrFnbTt-H1rJb-kXhjRsQI3NiiVu7DYD_L7kBLPvBzu4-ieXNB6Jb-ukQpHwujlzybaeirEyV0=s220

I see this behavior in the Drive v3 "Try This API" screen with all scopes authorized. I go to the thumbnailLink immediately after getting the response so it is not expired.

Edit: The webViewLink works for me in the case of a google slide. So I am allowed to see the full contents publicly using that link but still get a 404 with the thumbnaiLink. Based on that inconsistency this seems like a bug, not a security or permissions issue.

pkatsourakis
  • 1,024
  • 7
  • 20

3 Answers3

0

This is not a bug. You are not supposed to be able to access the thumbnailLink if you don't have access to the file's content, as indicated here.

As a workaround, I would propose your app or whoever has access to the thumbnail links to upload the thumbnails to Drive, so that users can access these Drive links. Anyway, I don't know the details of your project so I'm not sure this would be a feasible or desired workaround.

Iamblichus
  • 18,540
  • 2
  • 11
  • 27
  • Yes, I read the description of the property. That is an incredibly non-specific description. That is why I ask more specific questions. Also I would say I do have access to the file’s content if I can open the entire slide or document in the web browser. – pkatsourakis Oct 15 '19 at 11:39
  • Oh wait, can you access a document that is not public when you are not logged in your Google account? – Iamblichus Oct 15 '19 at 11:44
  • Yes I can. Is access to content supposed to only load if you are logged into the google account on a browser? – pkatsourakis Oct 15 '19 at 11:46
  • That is interesting behavior, is that in the API documentation? I think access to the `webViewLink` is based on the OAuth 2.0 scope used to authorize the user. So if you use an access token which includes the scope `https://www.googleapis.com/auth/drive` then you should have access to see any files [based on this reference](https://developers.google.com/identity/protocols/googlescopes#drivev3). – pkatsourakis Oct 15 '19 at 13:46
  • Sorry I misunderstood you. Yes of course, with that scope you should be able to access the file. – Iamblichus Oct 15 '19 at 13:59
  • I still can't load the thumbnail with that scope. That's why I'm confused about the behavior. – pkatsourakis Oct 15 '19 at 14:02
  • So how are you trying to access the URL? Can you provide a sample of the code you are working on? – Iamblichus Oct 16 '19 at 14:04
  • I'm able to reproduce the behavior in the ["Try this API" reference documentation filtering by google slides](https://developers.google.com/drive/api/v3/reference/files/list?apix_params=%7B%22q%22%3A%22mimeType%3D%27application%2Fvnd.google-apps.presentation%27%22%2C%22fields%22%3A%22files(name%2CmimeType%2CwebViewLink%2CthumbnailLink%2ChasThumbnail)%22%7D). All OAuth scopes are selected. I can load the URL from the `webViewLink` but I get a 404 from the `thumbnailLink`. – pkatsourakis Oct 16 '19 at 14:20
  • Hi @OMila please let me know if you need any more info/clarification or get any updates on this question. It will be appreciated! Thanks – pkatsourakis Oct 23 '19 at 15:31
  • 1
    I'm seeing this same behavior, have you found any workaround? – David Jan 08 '20 at 20:27
  • @David posted a solution. – Faraz Azhar Aug 25 '20 at 19:48
0

The reason why you are getting a 404 is that the binary documents' thumbnails are publicly accessible. If you can get your hands to the ThumbnailLink field of Google File, you can download the thumbnail images using a simple WebClient without any authentication.

However, if you're trying to download a Google Document's thumbnail image using WebClient that will give you a 404 error, because Google expects that you download this ThumbnailLink URI using an authenticated connection.

I had faced a similar problem and was able to resolve it very easily. I use Google Drive API (version 3) for accessing the documents on Google Drive. The Google API has already authenticated my account which is how I am able to acquire the ThumbnailLink in the first place. But instead of using WebClient, use the DriveService's HTTPClient to download the thumbnail. The HTTPClient in DriveService creates an authenticated HTTP request allowing you to download thumbnails for Google Documents as well.

  private async Task<bool> DownloadThumbnail(string thumbnailURL, string localFile)
        {
            try
            {    
                var client = DriveService.HttpClient;
                var response = await client.GetAsync(thumbnailURL);
                using (var fs = new FileStream(localFile, FileMode.CreateNew))
                    await response.Content.CopyToAsync(fs);
                
                return true;    
            }
            catch (Exception ex)
            {
                // log error
                return false;
            }
        }
Faraz Azhar
  • 562
  • 9
  • 28
0

Get thumbnail link with scopes drive and drive.readonly

It's private data Token or login required

https://drive.google.com/thumbnail?authuser=0&sz=w280&id=[fileid]

sz = size

w = width

GMKHussain
  • 3,342
  • 1
  • 21
  • 19