开发者

How to test Google+ and Facebook buttons?

I added custom Google+ and Facebook buttons, and counter is updated over MY ajax...

Here is the code ( I included for twitter counter too so it can be useful for others, but it's counter is working for sure ):

 $url = "URL OF PAGE";

 $ch = curl_init();  
 curl_setopt($ch, CURLOPT_URL, "https://clients6.google.com/rpc?key=AIzaSyCKSbrvQasunBoV16zDH9R33D88CeLr9gQ");
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $url . '","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]');
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
 $curl_results = curl_exec ($ch);
 curl_close ($ch);
 $parsed_results = json_decode($curl_results, true);
 echo $parsed_results[0]['result']['metadata']['globalCounts']['count']; //Google+ counter for this URL



 $fbresponse = file_get_contents('http://graph.facebook.com/' .$url);
 $fbresponse_c = json_decode($fbresponse,true);
 if ( $fbresponse_c['shares'] ) { echo $fbresponse_c['shares']; } else { echo '0'; } //Facebook counter for this URL

 $twresponse = file_get_contents('http://cdn.api.twitter.com/1/urls/count.json?url=' .$url. '&callback=twttr.receiveCount');
 $twresponse = str_replace('twttr.receiveCount(' ,'', $twresponse);
 $twresponse = str_replace(')' ,'', $twresponse);
 $twresponse_c = json_decode($twresponse,true);
 echo $twresponse_c['count']; //Twitter counter for this URL

I changed URL to "http://www.google.com" and it shows counters from all sites 3 sites...

I shared link on my Facebook Wall, using my pop-up ( code is below ) but counter didn't updated ( it didn't updated for two days )... And for Google+ I don't have account so I can't test it...

Can someone tell me way how to test those? Since from what I see it's not working...

For sharing I pop-up this URL for Facebook:

"http://www.facebook.com/sharer.php?u=" + escape(url) + "&t=Some text"

and this one for Google:

"https://plusone.google.com/u/0/+1/profile/?type=po&source=p&parent=https%3A%2F%2Fplusone.google.com&hl=en_US&ru=" + escape(urll)

How often facebook updates it's counters? And how can I check is this Google+ counter working okay?

Than开发者_StackOverflowks!


Everything is updating now... Facebook instantly, and I opened Google+ account so I tested that too, it's also working...

-Closed-

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜