0

像这样:

在此处输入图像描述

请参阅文章下的示例:

http://www.golem.de/news/server-prozessor-intel-bestaetigt-broadwell-als-xeon-fuer-sockel-1150-1311-102622.html

设计不是问题,但是如何获取这个 url 的 twitter、facebook 和 google plus 的分享数?

4

1 回答 1

0

找到了解决方案。以下是通过 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;
}

?>
于 2013-11-13T15:20:32.663 回答