Google云端硬盘网站上的访问控制 - 允许 - 来源错误 [英] Access-Control-Allow-Origin error on Google Drive web site

查看:257
本文介绍了Google云端硬盘网站上的访问控制 - 允许 - 来源错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google云端硬盘( https://googledrive.com/host/ .. )为主办一个非常简单的网站。在这个网站上,我使用jQuery load()函数来嵌入Google云端硬盘文档中的一些内容( https ://docs.google.com/document/ .. )。这一直很好...直到我今天检查它。



该网站不再显示文档中的内容,现在正在向控制台:

  XMLHttpRequest无法加载https://docs.google.com/document/d/1X1ZEtrGm8tnAvLIuzF4ch2dltVjIwQJl3Zn3bOLJS4s/pub。请求的资源上没有Access-Control-Allow-Origin标题。原因'https://googledrive.com'因此不被允许访问。 

任何人都可以请告诉为什么这个工作...现在不是......以及如何让它再次运作?



感谢您的协助。 看起来Google最近更改(或删除了)文档的 Access-Control-Allow-Origin 标题。我曾经通过 JS Google Drive SDK 获取文档的元信息,然后获取使用提供的导出链接和访问令牌,通过jQuery获取HTML内容。这是行不通的。



我在我的应用程序中实现了一个Web代理,并通过导出链接和访问令牌。



在Rails中(使用 HTTParty gem)控制器动作如下所示:

 def get_google_doc 
response = HTTParty.get(
params [:export_link],
{headers:{'Authorization'=&';'Bearer' params [:access_token]}}

render(text:response.parsed_response)
end

和JS请求一样:

  var request = jQuery.ajax({
url:/ get_google_doc,
type:GET,
dataType:html,
data:{
export_link :htmlExportLink,
access_token:accessToken
}
});

您可以在这里找到关于此主题的更多信息:




I'm using Google Drive (https://googledrive.com/host/...) to host a very simple site for a kiosk. On this site, I'm using jQuery load() function to embed some content from a Google Drive document (https://docs.google.com/document/...). This has been working great... up until I just checked it today.

The site is no longer displaying the content from the document and is now throwing an error in the console:

XMLHttpRequest cannot load https://docs.google.com/document/d/1X1ZEtrGm8tnAvLIuzF4ch2dltVjIwQJl3Zn3bOLJS4s/pub. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://googledrive.com' is therefore not allowed access.

Can anyone please advise on why this was working... and now it isn't... and how I can get it working again?

Thank you for your assistance.

解决方案

It seems that Google changed (or removed) the Access-Control-Allow-Origin header of documents recently. I used to get a document's meta info via the JS Google Drive SDK and then fetch the HTML content via jQuery using the provided export link and access token. This is not working any more.

I ended up implementing a web proxy in my application to which I pass the export link and access token.

In Rails (using the HTTParty gem) the controller action looks like this:

def get_google_doc
  response = HTTParty.get(
      params[:export_link],
      { headers: { 'Authorization' => 'Bearer ' + params[:access_token] } }
  )
  render(text: response.parsed_response)
end

And the JS request like this:

var request = jQuery.ajax({
    "url": "/get_google_doc",
    "type": "GET",
    "dataType": "html",
    "data": {
        "export_link": htmlExportLink,
        "access_token": accessToken
    }
});

You'll find more info on the topic here:

这篇关于Google云端硬盘网站上的访问控制 - 允许 - 来源错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆