admin管理员组

文章数量:1302270

There is a team drive full of PDFs.

I have set up oauth2 and can successfully login users. They can then enter in a file Id and my site will return all of the metadata for that file.

However I cannot seem to embed this PDF file. In the metadata there are two urls:

  • webContentLink
  • webViewLink

I tried creating an iFrame with both links but neither work.

Is this even possible to do?

I am using JS to do all of this and I am requesting the .metadata.readonly scope.

There is a team drive full of PDFs.

I have set up oauth2 and can successfully login users. They can then enter in a file Id and my site will return all of the metadata for that file.

However I cannot seem to embed this PDF file. In the metadata there are two urls:

  • webContentLink
  • webViewLink

I tried creating an iFrame with both links but neither work.

Is this even possible to do?

I am using JS to do all of this and I am requesting the https://www.googleapis./auth/drive.metadata.readonly scope.

Share asked Jan 8, 2018 at 13:02 RyanRyan 5419 silver badges28 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

webContentLink and the embeddable link have minor differences.

webContentLink:

https://drive.google./file/d/PDF_DRIVE_ID/view?usp=drivesdk

Embed URL:

https://drive.google./file/d/PDF_DRIVE_ID/preview

Right now, I haven't seen a direct API method to fetch the embedabble link but if you plan to do this by code, you can just manipulate the webContentLink so that it removes the view?usp=drivesdk part and replace it with preview.

Sample snippet:

<iframe src="https://drive.google./file/d/PDF_DRIVE_ID/preview" width="640" height="480"></iframe>

You can do this with an object tag like so:

<object data="https://drive.google./file/d/[id]/preview" type="application/pdf" width="100%" height="500px"></object>

Here's a nice place you can try that.

https://www.w3docs./tools/code-editor/1085

本文标签: javascriptEmbed PDF File Hosted on Google Drive on WebsiteStack Overflow