Google Docs thumbnail link returns 404 - google-drive-api
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.
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.
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;
}
}
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
Related
Does current Google Drive Api give option similar to downloadUrl with access token in query string?
Before January 1, 2020 Google Drive API allows to specify access token in query string. Therefore it was possible to get downloadUrl for video file in Google Drive, then to add access token as parameter in the query string and this url can be used as source url for html player in browser. Now in accordance with changes to the Google Drive API this way does not work. The article recommends to use webContentLink but it seems they require cookies. Therefore if user is not logged into corresponding Google account the webContentLink cannot be used as source url for html player as instead of content of the file it returns Google page for login. If I share the file then webContentLink returns the file content but this variant is not acceptable for me. I know that it is possible to download file in browser memory and then to use data url. But this variant is not good for big video file as before playing all file has to be download. Does Google Drive API offer at current moment an option similar to downloadUrl with access token in query string?
Google Slides video access via 'access_token'
My app requests the 'https://www.googleapis.com/auth/drive.readonly' permission from a user. When the app gets a Google access token, a url is built to access a user selected Google Slides presentation preview, something like: https://docs.google.com/presentation/d/1WADAfZShdqdYKgae8C9LdpYlPgf2qjoZD2jjKln4F3M/embed?rm=minimal&access_token=ya29..... This works great to view the presentation, but if a video is used on a slide, then follow error shows: Since my app is requesting full read access to a user's Google Drive, and the video in question is in the user's Google Drive, why is this happening?
This is happening because you still have to let other users have access to your video itself, therefore you need to share it to them like you would do it with any other kind of file inside your Drive. To do it programmatically, you will need to use the Drive API and build a request in the Files: update enpoint like this: [ { 'type': 'user', 'role': 'writer', 'emailAddress': 'user#example.com' }, { 'type': 'domain', 'role': 'writer', 'domain': 'example.com' } ] Edit For what I could understand now. To be able to see the video, do the following: 1) Right-click on the video. 2) Click Share. 3) Click "Advanced" (It is in the right-bottom corner). 4) Click "Change...". 5) Choose "On -Anyone with the link" and set the access as "Can Edit". When you use the "access_token" query parameter Google Slide is going to search for the video's URL in the Driver, which you have to set shareable permissions to the video. Images can be accessible from anyone who has access to the presentation as the doc says: An URL to an image with a default lifetime of 30 minutes. This URL is tagged with the account of the requester. Anyone with the URL effectively accesses the image as the original requester. Access to the image may be lost if the presentation's sharing settings change. Videos have to have the sharing settings configure as the doc says: An URL to a video. The URL is valid as long as the source video exists and sharing settings do not change. Notice the difference between the two here: Anyone with the URL effectively accesses the image as the original requester. Update I am updating my answer because I came across this, which states authorizing your requests through the access token query parameter to connect to the Drive API will be deprecated starting January 1, 2020. Therefore your requests now will need to be made using an HTTP header. My answer should be considered a workaround because it will be deprecated soon. Docs You can find more info about the Slides API and Drive API in the following links: Drive API v3. Share files, folders and drives. Slides API. Pages, Page Elements, and Properties.
Although you have stored your video in the same drive location alongside your presentation, I guess it might not be accessiable when it is "embedded within your slides". However, you would be able to access the video if you use the same access token to see the video alone. It would be better to store videos separately, embedded them in your presentation and then access them using their respective scopes instead. if you choose to take this route then, I think you need to allow the following scopes as well to access your video from the presentation viz drive.photos.readonly, youtube.force-ssl respectively. Alongside your other drive scopes, provided you have stored videos in either of the 2 ways mentioned below. Hence, at the time of access_token request, use the relevant scopes and get the access token and use the same for accessing your resources at a later point in time. 2 options, When using Drive API https://www.googleapis.com/auth/drive.photos.readonly View the photos, videos and albums in your Google Photos When using Youtube https://www.googleapis.com/auth/youtube.force-ssl See, edit, and permanently delete your YouTube videos, ratings, comments and captions Google API documentation - https://developers.google.com/identity/protocols/googlescopes
how to use PickerBuilder.setRelayUrl(string) in google picker API?
I need to get a shareable link to google drive photos and files. Do I need to know this method can be used for that or what can be used for that?
You can see the defined use for setRelay in Picker Class Reference: PickerBuilder.setRelayUrl(string) - Set the relay URL, used for gadgets.rpc. Picker.setRelayUrl(string) Specify a relay URL to circumvent cross-domain issues. However to answer your question, you might be looking for webViewLink: A link only available on public folders for viewing their static web assets (HTML, CSS, JS, etc) via Google Drive's Website Hosting. This property is returned from a successful API call like files.get or files.list.
Google Docs viewerng api reference
I am trying to show a file hosted in a public site inline on my web page using google docs by providing the following URL to an iframe. https://drive.google.com/viewerng/viewer?url='+link+'&embedded=true where link is the path to the file I want to show. I am facing some issues with showing files which require user authentication. Hence would like to see reference documentation for the API. I searched for it online was unable to find any reference documentation for the following service end point. "https://drive.google.com/viewerng/viewer"
Let requests originating from this Google service pass your authentication Include a secret parameter in the link to confirm that an authenticated user (of your site) is requesting the document (via viewerng)
Thumbnails of shared Google docs give 404
When I request file info via the Google Drive API for a Google Docs file that can be viewed by anyoneWithLink I get a thumbnailLink that produces a 404 Error if you view it as an anonymous user. Is there a way to get a thumbnail for such shared files that can be viewed by anyone? For Drawings I found https://docs.google.com/drawings/d/FILE_ID/image?w=WIDTH, but I didn't find anything for the other file formats.
Please use the thumbnailLink provided on the file resource. https://developers.google.com/drive/v2/reference/files#resource