简体   繁体   English

因此,不允许来源'http:// localhost:3000'访问Twitter API

[英]Origin 'http://localhost:3000' is therefore not allowed access Twitter API

I'm developing a web application that uses the Twitter API REST . 我正在开发使用Twitter API REST的Web应用程序。 I have a page with Twitter accounts and a button for adding a new account. 我有一个带有Twitter帐户的页面和一个用于添加新帐户的按钮。 When the button is pressed, the function in the Angular controller is executed: 按下按钮后,将执行Angular控制器中的功能:

 // Calls token to add a new Twitter user $scope.callToken = function () { $http.get('/token') .then(function (response) { console.log(response); }); }; 

This is the code in the backend to serve de request. 这是后端中用于处理请求的代码。 It simply redirects to Twitter to add a new user. 它只是重定向到Twitter以添加新用户。

 // routes.js var token = express.Router(); token.route('/token') .get(cuentasCtrl.getToken); // Account file exports.getToken = function(req, res) { twitter.getRequestToken(function(err, requestToken, requestSecret) { if (err) res.status(500).send(err); else { _requestSecret = requestSecret; res.setHeader('Access-Control-Allow-Origin', '*'); res.redirect("https://api.twitter.com/oauth/authenticate?oauth_token=" + requestToken); } }); }; 

But I get the next error: 但是我得到了下一个错误:

Origin 'http://localhost:3000' is therefore not allowed access Twitter API

My server is running on localhost:3000 and If I put localhost:3000/token in my browser there is no problem. 我的服务器在localhost:3000上运行,如果将localhost:3000 / token放在浏览器中,就没有问题。 I have read the solutions for using CORS and tested other browsers but it hasn't worked for me. 我已经阅读了使用CORS的解决方案,并测试了其他浏览器,但是它对我没有用。 What have i done wrong? 我做错了什么?

The redirect you are sending in your express response is caught by the http client you use in the frontend and the redirect happens there. 您在快速响应中发送的重定向被您在前端中使用的http客户端捕获,并且重定向在那里发生。 You are in a classical CORS situation and of course this is not how you can interact with the Twitter rest APIs. 您处于典型的CORS情况,当然,这不是您与Twitter rest API进行交互的方式。

You have to make http calls to Twitter on the node side (server to server) or use a client side client library for Twitter ( https://dev.twitter.com/web/javascript ) 您必须在节点侧(服务器到服务器)对Twitter进行http调用,或者对Twitter使用客户端客户端库( https://dev.twitter.com/web/javascript

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 因此,不允许访问源“ http:// localhost:3000”。 CryptoCompare.com API - Origin 'http://localhost:3000' is therefore not allowed access. CryptoCompare.com API 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问来源“ http:// localhost” - No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access XMLHttpRequest无法加载“此URL”来源Access:Control-Allow-Origin不允许使用原始http:// localhost:3000。 - XMLHttpRequest cannot load “THIS URL” Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin. 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问来源“ http:// localhost:4400” - No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4400' is therefore not allowed access - 请求的资源上没有“Access-Control-Allow-Origin”标头。 因此不允许Origin'http:// localhost:8100'访问 - — No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access Socket.io没有'Access-Control-Allow-Origin'标头出现在请求的资源上。 因此不允许Origin'http:// localhost'访问 - Socket.io No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access 请求的资源上不存在“Access-Control-Allow-Origin”标头。 因此不允许Origin'http:// localhost:8100'访问 - No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问来源“ http:// localhost:4200” - No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed accesss Google的Places API和JQuery请求-Access-Control-Allow-Origin不允许来源http:// localhost - Google's Places API and JQuery request - Origin http://localhost is not allowed by Access-Control-Allow-Origin CORS 策略已阻止从源“http://localhost:3000”访问“https://localhost:7144/api/employees” - Access to fetch at 'https://localhost:7144/api/employees' from origin 'http://localhost:3000' has been blocked by CORS policy
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM