14

I recently had a problem with the Google Drive API displaying my documents. We have developed a web application that is connecting to Google Drive accounts to retrieve a user's drive files, then display in an iframe the file using its embedUrl/alternateUrl.

This has worked fine for us in the past, but suddenly files other than Google Documents stopped displaying: html files, text files, doc 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, it means that Google is preventing the display of documents outside of the Google domain, but the question is "why suddenly now", and how to circumvent it.

If someone stumbled upon the same issue and have found a solution, I'd be glad to hear.

Thank you kindly.

Elior Boukho
  • 141
  • 1
  • 1
  • 3
  • I've found the following questions on the topic, but no descriptions as to why it is no longer working: http://stackoverflow.com/questions/21367610/showing-documents-from-google-drive-on-webpage – Rivero Dec 18 '14 at 22:10
  • http://stackoverflow.com/questions/9103154/how-can-i-embed-a-google-docs-collection-in-an-iframe – Rivero Dec 18 '14 at 22:10
  • Same problem too. I'm trying to embed a PDF on my CMS, but no chances. I've tried to generate a public link to allow embeding, but the problem persists. – jeferod83 Mar 02 '15 at 13:50
  • @jeferod83 did u find any solution for it. I need o use view link because i need download and print tools in the view – sowmya Jun 19 '20 at 14:14

2 Answers2

28
https://docs.google.com/file/d/0B_JkNS6Wu4b5R2c0YlJSN0oyQUE/preview?usp=drivesdk

Use preview instead of edit in the URL. It will work.

Mukesh Jeengar
  • 762
  • 9
  • 20
  • 2
    Is there any way to have the whole UI Editor of Google? The preview works but I need the editor. It does work, though. It's just annoying to see the error in the inspection console, makes me think eventually it will fail. – thelastinuit May 12 '17 at 15:58
0

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

This means you have 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 the google drive controls are not shown.