Here’s a simple way to show a facebook pages current number of likes, it combines JSON and PHP, very simple! Can be used Facebook Profiles/Pages, as well as edited to work for general links and websites.
<?php
function fb_likes_count(){
$data = json_decode(file_get_contents("https://graph.facebook.com/TrulyCode"));
echo $data->likes;}
fb_likes_count();
?>
At the time of writing that will output “91” (likes currently) straight away, just call the function
Example:
fb_likes_count();
where you want it echo’d.Example:
The number of likes on my Facebook page is: <?php fb_likes_count(); ?>
There is actually a lot more data available within that JSON object, here are the values returned that you can also hook onto if you wish:
{
"about": "Truly Code - all things internet, web development design and general web-tech information. http://trulycode.com",
"category": "Computers/technology",
"is_published": true,
"talking_about_count": 60,
"username": "trulycode",
"website": "http://trulycode.com",
"were_here_count": 0,
"id": "114477908707450",
"name": "Truly Code",
"link": "https://www.facebook.com/trulycode",
"likes": 91,
"cover": {
"cover_id": 199485470206693,
"source": "http://sphotos-a.ak.fbcdn.net/hphotos-ak-ash3/s720x720/945532_199485470206693_1447682729_n.jpg",
"offset_y": 0,
"offset_x": 0
}
}
0 comments:
Post a Comment