ajax - 来自常规服务器的 Twitter OEmbed URL "No-Access-Control-Allow-Origin"

标签 ajax angularjs http twitter

当我尝试根据 ID 获取推文的 html 时出现以下错误:

XMLHttpRequest cannot load https://api.twitter.com/1/statuses/oembed.json?id=484587947543781376. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://app-theysoundlike.rhcloud.com' is therefore not allowed access. 

如您所见,源不是 localhost,它位于 Openshift 上的常规服务器上。我正在使用以下 AngularJS 代码发出请求:

$http({
        url:'https://api.twitter.com/1/statuses/oembed.json?id='+data.id,
        method:"GET"
        }).success(function(data){
            $scope.tweetHTML = data.html;
            $scope.tweetAvailable = true;
        });
});

data.id 不是问题,因为 URL 的格式正确。实际请求失败。

最佳答案

尝试将 $http.jsonp 与 url 一起使用

https://api.twitter.com/1/statuses/oembed.json?id={{YOUR_ID}}&callback=JSON_CALLBACK

关于ajax - 来自常规服务器的 Twitter OEmbed URL "No-Access-Control-Allow-Origin",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24546768/

相关文章:

node.js - 带有 ObjectID 引用的 RESTful Mongoose

angularjs - 如何为单元测试提供模拟过滤器

python - 使用 python 套接字接收大型 http 请求

http - oauth2 错误 AADSTS90014 : The request body must contain the following parameter: 'grant_type'

c# - iOS http POST 请求

javascript - MooTools 事件监听器在 element.innerHTML 更改后消失

jquery - Spring Security Core authAjax,如何忽略 Referer

Jquery .live() 仍然无法正确运行函数

javascript - 转义码输入的 Keyup 问题

javascript - bootstrap btn-group 中的 angularjs 切换类