In my previous post I had explained about how to fetch facebook cover page using jQuery. Now I am going to explain how to get facebook fan page details using jQuery Ajax Method called – jQuery.getJSON()
Contents
jQuery Code will get you
- Fan Page Name
- Fan Page Cover Page
- People Talking about Count
- No of Likes
- About
- Username
- Fan Page Category
- Website Link
- Fan Page Link & much more
jQuery Code to fetch fan page details
//code to fetch fan page details
jQuery.getJSON('http://graph.facebook.com/'+username+'?callback=?', function(data){
var fb_count = data['likes'].toString();
var fb_about = data['about'].toString();
var fb_name = data['name'].toString();
var fb_category = data['category'].toString();
var fb_founded = data['founded'].toString();
var fb_talking_count = data['talking_about_count'].toString();
var fb_website = data['website'].toString();
var fb_link = data['link'].toString();
fb_count = add_commas(fb_count);
fb_talking_count = add_commas(fb_talking_count);
$('.facebook_about').html(fb_about);
$('.facebook_likes').html(fb_count);
$('.facebook_name').html(fb_name);
$('.facebook_link').html(fb_link);
$('.facebook_website').html(fb_website);
$('.facebook_talk_count').html(fb_talking_count);
$('.facebook_category').html(fb_category);
$('.facebook_founded').html(fb_founded);
$('.facebook_cover_page').html('<img src="'+ data.cover.source + '">');
});
Javascript Code for adding commas in numbers of four or more digits
function add_commas(number) {
if (number.length > 3) {
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : '');
for (i=0 ; i < Math.floor(number.length / 3); i++) {
if ((mod == 0) && (i == 0)) {
output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
} else {
output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
}
return (output);
} else {
return number;
}
}
Please don’t forget to share and subscribe to latest updates of the blog. Also any comments and feedback are all welcome!
Thanks!
how can i get the fans details of that page like their name or birthdays?
What about the picture (logo) ? Thanks !
Dear Yiidir,
You have to use this – http://graph.facebook.com/w3lessons.info/picture?type=large
Replace w3lessons.info with your unique page url
Thanks
I can’t use it with other fanpage, it only works with ‘w3lessons’. Please help me. THANKS
Hi Sfantu,
Just now i checked with “google”, “mashable” … its working fine,,
Please check
Thanks, You’re right, it works with “google”, “mashable”. But i can’t use it with other like “BVBorussiaDortmund09” , “NowYouSeeMeMovie”. Could you tell me which kind of page I can use it with ? THANKS
Hi Sfantu,
I have modified the code little bit.. Now its working with “NowYouSeeMeMovie”, “BVBorussiaDortmund09”
I have added this line –
if(data[‘founded’]) {
var fb_founded = data[‘founded’].toString();
}
Thanks
It works, thank you very much Karthikeyan