How To Calculate Facebook Like, Twitter, Pin It and Google Plus Count With PHP

For Facebbok Like count,

$url = “http://allfacebook.com/calculate-facebook-like_b44023”;
$json_string = file_get_contents(‘http://api.facebook.com/restserver.php?method=links.getStats&urls=’.$url);
$xml = (array)simplexml_load_string($json_string);
print_r($xml);

 

For Twitter count,

$url = “http://blog.chapagain.com.np/magento-send-confirmation-email-on-new-customer-registration/”;
$json_string = file_get_contents(‘http://cdn.api.twitter.com/1/urls/count.json?url=’.$url.’&callback=?%27&callback=?&format=json’);
$json = json_decode($json_string, true);
print_r($json);

 

For Pin It count,

$url = “http://oss1.magentoprojects.net/fablogue/jewelry/caviar-ring.html”;
$json_string = file_get_contents(‘http://api.pinterest.com/v1/urls/count.json?callback=&url=’.$url);
$json = json_decode(str_replace(‘)’,”,str_replace(‘(‘,”,$json_string)), true);
print_r($json);

 

For Google Plus count,

$url = “http://blog.chapagain.com.np/magento-send-confirmation-email-on-new-customer-registration/”;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, “https://plusone.google.com/_/+1/fastbutton?bsv&size=tall&hl=it&url=”.urlencode($url));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$html = curl_exec ($curl);
curl_close ($curl);
$doc = new DOMDocument();
$doc->loadHTML($html);
$counter=$doc->getElementById(‘aggregateCount’);
echo $counter->nodeValue;

 

Thats it!!

 

Advertisements
  1. and .. .how to use it ??

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: