Skip to content

Instantly share code, notes, and snippets.

@andrefrd
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrefrd/9520512 to your computer and use it in GitHub Desktop.
Save andrefrd/9520512 to your computer and use it in GitHub Desktop.
/*
*Função PHP Google +1 Count
*Author: André Dantas
*email: andrefrd (at) gmail (dot) com
*/
function gPlusCount( $url ) {
$contents = file_get_contents( 'https://plusone.google.com/_/+1/fastbutton?url=' . $url );
preg_match( '/window\.__SSR = {c: ([\d]+)/', $contents, $matches );
if( isset( $matches[0] ) )
return (int) str_replace( 'window.__SSR = {c: ', '', $matches[0] );
return 0;
}
gPlusCount($url);
/*
*Função JavaScript + jQuery Social Count
*Facebook + Twitter + Pinterest
*Author: André Dantas
*email: andrefrd (at) gmail (dot) com
*/
function funcaoCountSocial(url){
var urlfb = 'https://graph.facebook.com/?id='+url;
$.ajax({
url:urlfb,
dataType: 'json',
'async' : true,
success:function(data){
$("span#count-fb").html(data.shares);
},
});
var urltwt = 'https://cdn.api.twitter.com/1/urls/count.json?url='+url;
$.ajax({
url:urltwt,
dataType: 'jsonp',
'async' : true,
success:function(json){
$("span#count-twt").html(json.count);
},
});
var urlpin = 'https://api.pinterest.com/v1/urls/count.json?url='+url;
$.ajax({
url:urlpin,
dataType: 'jsonp',
'async' : true,
success:function(json){
$("span#count-pins").html(json.count);
},
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment