Skip to content Skip to sidebar Skip to footer

How To Read Facebook Feeds Using Json Format In Javascript

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 $('d

Solution 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>​

Solution 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.

Post a Comment for "How To Read Facebook Feeds Using Json Format In Javascript"