Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permanent links to thumbnails in Google Drive API

Tags:

I'm using Google Drive API (PHP) to upload some photos to my Drive. When a file is uploaded, a Google_DriveFile object is returned in the response to confirm the successful transfer. It includes a field called thumbnailLink, accessible through the getThumbnailLink getter. Its content may look like this:

https://lh4.googleusercontent.com/dqVdU195R4_0ZtWxsJlhW1Fr2K30xa2hH3V1KV4UrTBl9QkhOSR0ZqN9HoB-TjEQv8SIJw=s220

Until today, I was sure that the link doesn't change by itself over time. However, when I tried to display a thumbnail of a photo I have on my Drive, using a cached address I keep in my local database, I got a 403 error - you can see it under the mentioned link. I asked the API for the current link to the thumbnail and it's now completely different.

It happened to me only once but for multiple files, i.e. all the files I had on my Drive suddenly got new thumbnail links.

Is there a way to quickly retrieve a thumbnail of a document (preferably, a photo) by some constant value or to be sure that it won't change? The perfect solution would be to access the thumbnail under a link that includes the document's id instead of some hash that may change.

like image 505
PiotrK Avatar asked Sep 03 '14 15:09

PiotrK


1 Answers

Try this:

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

Where:

  • sz is a size, where you may use as w (width), as h (height)
  • fileid is a file id. You may find it in "share" menu by right click in Google Drive UI.
like image 58
user5132772 Avatar answered Sep 21 '22 13:09

user5132772