总份额

时间:2014-01-03 11:42:04

标签: php wordpress

我正在尝试获取WordPress博客所有共享的总数。我用谷歌搜索并找到了这个小脚本,但它没有正确计算所有份额。

<?php
function get_shares($url) {    
  $json_string = file_get_contents("http://www.linkedin.com/countserv/count/share?url=$url&format=json");
  $json = json_decode($json_string, true);
  return intval( $json['count'] );
}
function get_tweets($url) {

    $json_string = file_get_contents('http://urls.api.twitter.com/1/urls/count.json?url=' . $url);
    $json = json_decode($json_string, true);

    return intval( $json['count'] );
}

function get_likes($url) {

    $json_string = file_get_contents('http://graph.facebook.com/?ids=' . $url);
    $json = json_decode($json_string, true);

    return intval( $json[$url]['shares'] );
}

function get_plusones($url) {

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, "https://clients6.google.com/rpc");
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, 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($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
    $curl_results = curl_exec ($curl);
    curl_close ($curl);

    $json = json_decode($curl_results, true);

    return intval( $json[0]['result']['metadata']['globalCounts']['count'] );
}
function total($url){
    return get_tweets($url) + get_shares($url) + get_likes($url) + get_plusones($url); }
?>


<span class="pm-label"><?php echo total("http://pypix.com/roundups/best-python-2013/"); ?>
                                    Share</span>

此脚本总计214股,但实际为417股。

请帮帮我们。

1 个答案:

答案 0 :(得分:2)

将此选项添加到curl:

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

这应该让谷歌加上工作。找到答案HERE