![](/img/trans.png)
[英]Refused to load the script because it violates the following Content Security Policy directive
[英]REST API Error: Refused to connect to … because it violates the following Content Security Policy directive:
我正在尝试使用REST API将我在Twitter上的状态更新为“更新状态”。
我将其发布在Twitter自己的网站上,这是我发布的内容:
$.post("https://api.twitter.com/1.1/statuses/update.json?status=Hello")
但是我得到了错误
拒绝连接到“ https://api.twitter.com/1.1/statuses/update.json?status=Hello ”,因为它违反了以下内容安全策略指令:“ connect-src graph.facebook.com pay.twitter。 com analytics.twitter.com upload.twitter.com'self'“。
有人可以帮忙吗? 我只是发现Twitter教程有点混乱; 我要做的就是使用可以轻松发送推文的api。 我需要在Chrome扩展程序中执行此操作吗?
您需要将api.twitter.com
添加到您的CSP中:
<meta http-equiv="Content-Security-Policy"
content="connect-src graph.facebook.com
pay.twitter.com analytics.twitter.com
upload.twitter.com api.twitter.com 'self'">
不确定您当前的内容安全策略是什么样子,但是需要向其中添加正确的域( api.twitter.com
)。 顺便说一句,这将在您的index.html
。
如果您想查看这些文档,请从MDN“使用内容安全策略”中签出。
您可以在manifest.json
更改CSP(请阅读docs ):
{
...,
"content_security_policy": "[POLICY STRING GOES HERE]"
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.