如何获取特定URL在Google+上共享的次数


How to get the number of times a particular URL has been shared on Google+?

我正在使用我网站上的Google+共享链接,让访问者在Google+上共享特定页面

例如:

https://plus.google.com/share?url=http://example.com

如何获取特定URL被共享的次数?

请注意:我不想得到一个页面被+1'd的次数。

您可以使用Google+Ripples(about)跟踪股票数量。然而,目前还没有一个官方的API,可能永远也不会。

使用以下代码段分析共享数量:

$shares_url = 'https://plus.google.com/ripple/details?url='. $url;
$response = file_get_contents( $shares_url );
$shares_match = preg_match('@<div[^0-9]*([0-9]+) public share[s]?'.</div>@',$response,$matches);
if (!empty($matches)) {
    $shares = $matches[1];
} else {
    $shares = 0;
}
echo $shares;

注意,regex试图尽可能接近地指定数字,因为页面右侧可能也有一条注释,上面写着类似的内容

我的10股公开股票!

否则也会匹配。