Cannot embed Google Drive files in iframes

I recently had a problem with the Google Drive API displaying my documents. We developed a web application that connects to Google Drive accounts to extract user drive files, and then displays the file in an iframe using its embedUrl / alternateUrl.

This worked great for us in the past, but suddenly files other than Google Documents stopped displaying: html files, text files, document files ... even images!

The error I get is Refused to display 'https://docs.google.com/file/d/0B_JkNS6Wu4b5R2c0YlJSN0oyQUE/edit?usp=drivesdk' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

I understand the error, this means that Google prevents the display of documents outside the Google domain, but the question is “why suddenly now” and how to get around it.

If someone came across the same problem and found a solution, I would be glad to hear.

Thank you.

+6
source share
2 answers
 https://docs.google.com/file/d/0B_JkNS6Wu4b5R2c0YlJSN0oyQUE/preview?usp=drivesdk 

Use the preview instead of edit in url. He will work.

+14
source

I had the same problem and I found the following workaround showing google file files as webpage resources https://support.google.com/drive/answer/2881970?hl=en

This means that you need to extract the [doc id] from your URL and change your link to: http://www.googledrive.com/host/ [doc id]

Please note: in this case, Google controls are not displayed.

0
source

Source: https://habr.com/ru/post/1209320/


All Articles