Fetching Facebook, twitter button values in php

posted in: PHP, Social Networking | 0

Summary:

To get Facebook likes, share, comments

$source_url = “http://www.flightpodcast.com/episode-6-john-bartels-qantas-qf30”;
$url = “http://api.facebook.com/restserver.php?method=links.getStats&urls=”.urlencode($source_url);
$xml = file_get_contents($url);
$xml = simplexml_load_string($xml);
echo “<b>Shares:</b> “.$shares = $xml->link_stat->share_count;
echo “<b>Likes:</b> “.$likes = $xml->link_stat->like_count;
echo “<b>Comments:</b> “.$comments = $xml->link_stat->comment_count;
echo “<b>Total:</b> “.$total = $xml->link_stat->total_count;
To get Twitter retweets

$url = urlencode($url);
$twitterEndpoint = “http://urls.api.twitter.com/1/urls/count.json?url=%s”;
$fileData = file_get_contents(sprintf($twitterEndpoint, $url));
$json = json_decode($fileData, true);
unset($fileData);// free memory
echo $json[‘count’];

Previous Post
Next Post

Leave a Reply