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 - Forbidde
We've recently made a change to fix this issue. Please try your code again and see if you are still getting this error. I was able to run the following code to successfully download a thumbnail of my Google Document.
# Get oauth credentials
...
# Authorize an http object
http = httplib2.Http()
http = credentials.authorize(http)
drive_service = build('drive', 'v2', http=http)
# Google Document type ID
docId = '1ns9x5BMIZAeUR-eXerqgpaHBBGkl_-_KCVpVoV5opn8'
files = drive_service.files().get(fileId=docId).execute()
thumbnailLink = files['thumbnailLink']
print 'Downloading thumbnail at: ', thumbnailLink
response, content = http.request(thumbnailLink)
print response.status
with open('thumbnail.jpg', 'wb') as f:
f.write(content)
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.
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.