youtubev3api搜索在Chrome中失败,但在Firefox中有效



我们的应用程序Accessible Youtube多年来一直运行良好。现在它只适用于Firefox。Chrome当前的故障点是在搜索视频时。代码看起来像:

$.ajax(
"https://www.googleapis.com/youtube/v3/search?part=snippet&q=" +
q +
"&type=video&videoEmbeddable=true&key=OURKEYISHERE",
{
type: "GET",
cache: false,
success: function (data, status, jqxhr) {
build(data);
},
error: function (data, status, jqxhr) {
alert("An unknown error occured! Are you connected to the internet?");
},
}
);

在Firefox中,这很好用。在Chrome中,我们收到403响应,消息为

{
"error": {
"code": 403,
"message": "Requests from referer https://www.cs.unc.edu/ are blocked.",
"errors": [
{
"message": "Requests from referer https://www.cs.unc.edu/ are blocked.",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}

我怀疑这一定是Chrome最近处理cookie和/或跨来源请求的方式发生了变化。

我发现了问题。Chrome现在只发送referrer字段中的域。Firefox会将整个路径发送到页面。

我对API密钥有一个完整的路径限制。当我将限制更改为只需要域时,它又开始工作了。

这似乎是Chrome在API方面的一个突破性变化。

相关内容

最新更新