问题
This is my fee url in json format here
I want to know how to get the post content,title,likes,comment using jquery getJSON method. Any help woulld be appricated ?
JQUERY CODE
$("document").ready(function() {
$.getJSON("https://www.facebook.com/feeds/page.php?id=397319800348866&format=json", function(data) {
$("#div-my-table").text("<table>");
$.each(data, function(i, item) {
$("#div-my-table").append("<tr><td>" + item.EncoderName + "</td><td>" + item.EncoderStatus + "</td></tr>");
});
$("#div-my-table").append("</table>");
});
});
HTML CODE
<table id="div-my-table">
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td></td></tr>
</table>
回答1:
Use jquery getJSON() with a callback=? so it will use JSONP. You must use some api like graph graph.facebook.com Something like the below.
$.getJSON('https://graph.facebook.com/397319800348866?callback=?', function(data) {
console.log(data);
$('#likes').text(data.likes);
})
.success(function() { console.log('success'); })
.error(function() { console.log('error'); })
.complete(function() { console.log('complete'); });
HTML
likes: <div id='likes'></div>
回答2:
You can't, as the feed is at a different domain to the one you'll be running your Javascript on and you can't do cross-domain requests with AJAX.
You'll need to implement a server-side solution using PHP or similar to fetch the data and regurgitate it as JSON and then use your AJAX to load your local, same-domain script.
来源:https://stackoverflow.com/questions/13945990/how-to-read-facebook-feeds-using-json-format-in-javascript