如何为facebook、twitter和google plus制作个人共享按钮

如何为facebook、twitter和google plus制作个人共享按钮,facebook,button,twitter,share,Facebook,Button,Twitter,Share,像这样: 请参阅以下文章中的exmaple: 设计不是问题,但如何获得twitter、facebook和google plus的此url的共享数量?找到了解决方案。以下是如何通过API获取计数: <?php if ($network == 'facebook') { $string = file_get_contents('http://graph.facebook.com/?id=' . $current_url); $array = json_dec

像这样:

请参阅以下文章中的exmaple:


设计不是问题,但如何获得twitter、facebook和google plus的此url的共享数量?

找到了解决方案。以下是如何通过API获取计数:

    <?php   

if ($network == 'facebook')
{
    $string = file_get_contents('http://graph.facebook.com/?id=' . $current_url);
    $array = json_decode($string, true);
    if (isset($array['shares']))
        $number = intval($array['shares']);
    else
        $number = 0;    
}
elseif ($network == 'twitter')
{
    $string = file_get_contents('http://urls.api.twitter.com/1/urls/count.json?url=' . $current_url);
    $array = json_decode($string, true);
    if (isset($array['count']))
        $number = intval($array['count']);
    else
        $number = 0;        
}
elseif ($network == 'googleplus')
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "https://clients6.google.com/rpc");
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"'.$current_url.'","source":"widget","userId":"@viewer","groupId":"@self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
    $curl_results = curl_exec($curl);
    curl_close ($curl);
    $array = json_decode($curl_results, true);
    if (isset($array[0]['result']['metadata']['globalCounts']['count']))
        $number = intval($array[0]['result']['metadata']['globalCounts']['count']);
    else
        $number = 0;
}

?>