Skip to content

@mhawksey /gist:3833072

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Bulk collect social share counts from Facebook, Twitter, Delicious, Pinterest and Google +1s and return json
$url = $_GET['url'];
$finfo = json_decode(file_get_contents(''.$url.'&format=json'));
$tinfo = json_decode(file_get_contents(''.$url));
$dinfo = json_decode(file_get_contents(''.$url));
$pinfo = json_decode(preg_replace('/^receiveCount\((.*)\)$/', "\\1",file_get_contents(''.$url)));
$gplus = gplus_shares($url);
function gplus_shares($url){
// G+ DATA
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p",
"params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
$result = curl_exec ($ch);
curl_close ($ch);
return json_decode($result, true);
$output = array(
'facebook'=> isset($finfo[0]) ? $finfo[0]->total_count : NULL,
'twitter'=> isset($tinfo->count) ? $tinfo->count : NULL,
'delicious'=> isset($dinfo[0]) ? $dinfo[0]->total_posts : NULL,
'pinterest'=> isset($pinfo->count) ? $pinfo->count : NULL,
'googlePlus'=> isset($gplus[0]['result']) ? $gplus[0]['result']['metadata']['globalCounts']['count'] : NULL
header('Content-Type: text/javascript');
echo "[".json_encode($output)."]";

hello there, there's a new way to get the different social counts, check this link the code was so handy and useful, you can also use it as much as you want. Sparky!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.