Embed private google slides publicly with access token - google-drive-api

I want to create a website where users can see private google slides after logging in into my website. I will have the access token for the account which holds the ownership of those private files.
What I want to do is display the private files to my website users after they log in.
Right now I can display the private files by downloading them via an API and display it in a custom pdf viewer with pdf.js but I want to know is if there is any way to display private presentations with Google's embedded viewer maybe with some type of token (I don't want to force the user to sign in to their Google account. Also, note that I have an access token for those files).

Related

Anonymous read-only access to Google Drive API

I'm trying to implement anonymous read-only access to files stored in Google Drive via the Drive JS API. The Google Drive belongs to a Service Account and all files are configured to permit public read-only access. Anyone with the URL can currently access the Drive UI (in a web browser) and view these files without authentication.
My goal is to show information about these files on a separate web page using data retrieved via JS API, however it appears that Google only supports access to the API if the API client (the web page) is authenticated or the end user (the viewer of a web page) is authenticated via OAuth. Given that the files are already public it seems like it should be possible to provide anonymous read-only access via the API.
There are examples of an API client authenticating using a credentials JSON file containing credentials for a Service Account, instead of requiring the end user to authenticate via OAuth, but this requires the client to submit a JSON file when authenticating. As this is a web page I would need to embed the credentials JSON (including Private Key) in my public-visible source and this is not a good idea.
One option is to write my own API that authenticates (server-side) with Google Drive using a credentials JSON file and essentially proxies anonymous requests from my web page to the Google Drive API, but that seems like too much work for something that I believe should be simple.
Is there any way to provide anonymous read-only access to public Google Drive files via the JS API?

can i embed a private file of google drive api on my website? (the file has read permission of domain the my website)

the file has read permissions for my domain
but when embedding the file on my google website
reject the embed
code of iframe
<iframe src="https://drive.google.com/file/d/172YjAlA4ZtXzaaHGXORRX-687k78Rsra/preview" width="640" height="480">
I appreciate any help, and if you ask me why I want to show a private file on my website, it is because there is a login through which I only let my users enter
YOu can not embed a private google drive on your website because in order to access that drive a user would need to have permission to it.
You are probably using the webContentLink as the link you are trying to display there is also no way to send authorization in the form of an access token along with this link. THe user themself must have access to the file to be able to download it.
You could try creating a sharable link manually on the Google Drive website and use that link you can set that link to be valid for anyone with the link. But this will be a manual thing as far as i know you can not create these types of links though the website.

Creating Video with Private Link via API

I'm scoping out a project with the Vimeo API in which a user uploads a protected video.
I see the API allows for uploading a video with a password via privacy.view.
However, Vimeo also has the ability to upload a video that's only sharable with a private link. I'm not seeing a reference in the API that indicates it's possible to create this via the API. Basically, a user would upload a private video and the API returns the "private link" for that video.
I was hoping someone with more expertise might be able to confirm.

Google Docs thumbnail link returns 404

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

What is the main difference with picker api and OAuth JS-example

google picker api doesnt force the user to an OAuth dialog, no asking them to authorize the application to upload or request active user data. In the quickstart guide "https://developers.google.com/drive/quickstart-js" there is a simple example to upload a file for active user .The user must accept the application. What is the main difference with picker api and OAuth JS-example.
Can I write a code like picker api for active user
I want to upload and list active user drive data without using picker api
The picker does two things which you can't do manually in a third-party application:
Uses cookie auth for the currently logged in Google user
Adds the file to the drive.file scope's opened with files, so an app with the file scope can access it.