为什么我的 Javascript 在本地服务器上运行时无法访问 Twitter?
我创建了一个 html 页面,该页面使用基于找到的代码的 Javascript 这里。
当 html 作为文件直接加载到浏览器中时,它可以正常工作。不过,我尝试将它与 Chrome 插件结合使用,该插件不适用于作为文件访问的网站。
为了解决这个问题,我使用命令 python -m SimpleHTTPServer 设置了一个简单的网络服务器,但是当以这种方式访问网页时,它似乎无法访问来自 Twitter 的信息。
这是为什么?
如果我可以授予插件处理文件的权限,这也可以作为替代解决方案,这样我就不必使用网络服务器方法。但我不知道该怎么做。
这两种解决方案都适合我。
I created an html page that uses Javascript based off of the code found here.
It works correctly when the html is loaded directly into the browser as a file. However I'm trying to use it in conjunction with a Chrome plugin that doesn't work on websites accessed as a file.
To solve this problem, I set up a simple webserver with the command python -m SimpleHTTPServer
but when the webpage is accessed this way it doesn't seem to be able to access information from Twitter.
Why is that?
If I could give permission to the plugin to work on files, this would also work as an alternate solution so that I do not have to use the webserver method. I do not know how to do this though.
Either solution works for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的清单文件中,您需要允许访问数据所在的域,因此,如果您尝试访问
api.twitter.com
,您的 manifest.json 文件将看起来有点像这样:在 Google Chrome 中管理扩展程序,您可以启用开发人员模式并检查 background.html 页面以查找控制台中的错误。
in your manifest file you need to allow access to the domain where the data is located, so if your trying to access
api.twitter.com
you manifest.json file would look a little like so:Also in Manage Extension in Google Chrome you you can enable developer mode and inspect your background.html page to find errors in the console.