Wednesday, September 5, 2012

Facebook fanpage & Twitter followers counter by php



Facebook fanpage counter code:


[php]

<?php
# facebook fanpage counter

# top page: facebook, youtube
$page_id = "GSFBD";

# set facebook graph api
$query = "https://graph.facebook.com/$page_id";

# get content
$content = file_get_contents($query);

# decode from json
$decode = json_decode($content);

# get likes of page
$count = $decode->likes;

# set for number format (optional)
$count = number_format($count);

# get image avatar

# show counter
echo 'GSFBD : '.$count.' people like';
?>

[/php]

Output: GSFBD : 1,369 people like

Twitter followers counter code:

[php]

<?php
# counter twitter followers
# top5 : justinbieber, gsfbd

$username = "gsfbd";

# set username link
$api_page = 'http://twitter.com/users/show/' . $username;

# set xml content
$xml = file_get_contents ( $api_page );

# create xml element
$profile = new SimpleXMLElement ( $xml );

# get xml child
$count = $profile->followers_count;

# set for number format (optional)
// $count = number_format($count);

echo 'GSFBD : '.$count.' people follow';

?>

[/php]

Output: GSFBD : 26 people follow

2 comments:

  1. I just want to say I am new to blogging and site-building and seriously liked your web site. Likely I’m going to bookmark your blog post . You really have very good stories. Cheers for revealing your webpage.

    ReplyDelete
  2. hi I was luck to look for your theme in yahoo, your Topics is impressive, I learn a lot in your Topics really thanks very much, btw the theme of you blog is really wonderful, where can find it

    ReplyDelete

Note: Only a member of this blog may post a comment.