![](/img/trans.png)
[英]Origin null is not allowed by Access-Control-Allow-Origin (Synchronous, no jQuery)
[英]Jquery (jfeed) - Origin xxxxx is not allowed by Access-Control-Allow-Origin
我正在使用jFeed嘗試檢索 Facebook 頁面的 RSS 提要。 我可以手動導航到 RSS 就好了( https://www.facebook.com/feeds/page.php?format=atom10&id=12345 )但是當我嘗試使用以下代碼時,我最終得到錯誤“Origin Access-Control-Allow-Origin 不允許 xxxxx。”
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 交互。
您可以查看https://github.com/dawanda/jquery-rss 。 它使用谷歌的提要 API。
剛開始工作.,! 我使用應用程序 ID 和密碼獲取 access_token,然后使用 jquery getJSON 方法獲取數據。 像魅力一樣工作,不需要 facebook 身份驗證!!!
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
});
});
});
};
顯然,除了“警報”之外,您還想做一些其他事情,但它確實有效。 與我發現的任何其他東西相比非常簡單。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.