当我尝试根据 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/