jQuery(jfeed)-Access-Control-Allow-Origin不允许来源xxxxx [英] Jquery (jfeed) - Origin xxxxx is not allowed by Access-Control-Allow-Origin
问题描述
我正在使用 jFeed 来尝试检索Facebook页面的RSS feed.我可以手动导航到RSS很好( https://www.facebook.com/feeds/page.php?format=atom10&id=12345 ),但是当我尝试使用以下代码时,出现错误 Access-Control-Allow-Origin."
I'm using jFeed to try to retrieve a Facebook page's RSS feed. I can manually navigate to the RSS just fine (https://www.facebook.com/feeds/page.php?format=atom10&id=12345) but when I try to use the following code, I end up with the error "Origin xxxxx is not allowed by Access-Control-Allow-Origin."
jQuery.getFeed({
url: 'https://www.facebook.com/feeds/page.php?format=atom10&id=12345',
success: function (feed) {
alert(feed.title);
}
});
我假设是因为它需要OAuth 2.0,但我确实需要静音"解决方案,因此人们无需拥有Facebook帐户或以任何方式与Facebook互动
I'm assuming this is due to it requiring OAuth 2.0, but I really need a "silent" solution so people don't have to have a Facebook account or interact with Facebook in any way.
推荐答案
就可以了!!!我正在使用应用程序ID和密码来获取access_token,然后使用jquery getJSON方法来获取数据.像魅力一样工作,不需要Facebook身份验证!!!
Just got it working!!! I'm using the app ID and secret code to get the access_token and then using the jquery getJSON method to get the data. Works like a charm, no facebook auth required!!!
appID = '' //myappid
secretCode = '' //app "secret code"
authURL = 'https://graph.facebook.com/oauth/access_token?client_id=' + appID + '&client_secret=' + secretCode + '&grant_type=client_credentials'
feedURL = 'https://graph.facebook.com/' + appID + '/feed?'
function getFeed() {
$.get(authURL, function (accessToken) {
$.getJSON(feedURL + accessToken, function (data) {
$.map(data.data, function (item) {
alert(item.message);
//type: status, photo
//likes.count
//from.name
//created_time
});
});
});
};
很明显,您除了警报"外还想做些其他事情,但是它可以工作.与我发现的其他任何东西相比,都非常简单.
Obviously you'd want to do something besides "alert", but it works. Quite simple compared to anything else I've found.
这篇关于jQuery(jfeed)-Access-Control-Allow-Origin不允许来源xxxxx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!