Skip to content

Instantly share code, notes, and snippets.

@foo9
Created October 10, 2014 13:25
Show Gist options
  • Save foo9/adf67e73966cec76b2f6 to your computer and use it in GitHub Desktop.
Save foo9/adf67e73966cec76b2f6 to your computer and use it in GitHub Desktop.
Fetch Facebook Like Count Sample
function fetchFbLikeCount(url) {
return $.ajax({
dataType: 'json',
url: 'http://graph.facebook.com/?id=' + encodeURI(url)
}).done(function(data) {
console.log(url, data.shares);
});
}
var urls = [
'https://angularjs.org/',
'http://backbonejs.org/',
'http://knockoutjs.com/',
'http://emberjs.com/',
'http://vuejs.org/'
];
var $dfd = fetchFbLikeCount(urls[0]);
for (var i = 1, len = urls.length; i < len; i++) {
(function(i) {
$dfd = $dfd.then(function() {
return fetchFbLikeCount(urls[i]);
});
})(i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment