Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Drive - Unable to download thumbnails with an authenticated (OAuth2) request

For all Google Docs, I'm not able to download the thumbnail image from the ThumbnailLink property returned with a file response.

I always receive a '403 - Forbidden' error page with a message similar to this:

Your client does not have permission to get URL /thumbnailLink from this server.

(Client IP address: clientIP)

Unuthorized User

I try to use the class MediaDownloader.cs provided by Google and I also try to download it by using this code:

using (Stream stream = service.HttpClient.GetStreamAsync(p_DownloadUrl).Result) {
    StreamUtilities.Copy(p_WriteDelegate, stream.Read);
}

where 'service' is a DriveService (IClientService) object properly instantiated. I can use it to download the file or make any other requests. I use the 'Drive.Readonly' scope.

I didn't have any issue to download the Thumbnail for a Word, Excel, PDF, etc. documents, because these links are public and doesn't require any kind of authentication.

What I don't do correctly?

Is it possible to download the thumbnail for a Google Docs document?

like image 348
mtheriault Avatar asked Apr 22 '14 15:04

mtheriault


2 Answers

EDIT: This issue has now been fixed. See answer by Kalyan Reddy.

I also believe that this is an issue on Google's side. It makes no sense that you can download or export a file using an OAuth2 authenticated request, but not download a thumbnail of that same file. Another inconsistency is that this only affects Drive native formats such as application/vnd.google-apps.document. For example, I can get a thumbnail of document.docx, but not of the Drive document converted from it.

I was wondering how Google does it in their own apps and if I am using the API wrong. Turns out they use a private API for thumbnails:

https://googledrive.com/thumb/{file_id}
https://googledrive.com/thumb/{file_id}?width=500&height=500
https://googledrive.com/thumb/{file_id}?width=500&height=500&crop=false

This API works with the same OAuth2 token as Drive API v2.

I don't know exactly what Google's policy is on using undocumented APIs. Some of them are off limits or you need a permission to use them. This may fail your app review if you use it, but if you really need thumbnails right now, it is there. Otherwise you should wait for them to fix the issue on the public API.

Undocumented APIs also have no deprecation policy, so it might disappear without a warning. That said, I expect this one to be around for a while.

like image 99
Indiganflow Avatar answered Nov 05 '22 18:11

Indiganflow


As far as I can tell, this is a bug with the Google Drive API. As you've stated, this problem appears only for Google Docs format documents, not uploaded files.

I am getting the exact same type of error message as described in my post.

Also as you mentioned I believe this had been working a short time ago.

The problem we're getting now didn't happen when we were using the deprecated Document List API. We're switching to the Google Drive API with OAuth2 as part of updating our marketplace application in order to be listed on the V2 Marketplace.

It has been extremely frustrating to not have any feedback from Google developers who are probably the only ones that can reply about whether this is a problem with the Drive API.

like image 25
cwjos Avatar answered Nov 05 '22 19:11

cwjos