手动改进facebook喜欢,分享计数不起作用

时间:2016-06-27 10:12:13

标签: php facebook

手动获取类似的数量,之前似乎工作的共享现在无法正常工作。 $lines返回了喜欢和分享的数量。获取我使用以下值的值:

$postUrl = urlencode(SITEROOT.'gallery_single.php?photo_id='.$rasActImg['id'].'&format=xml');
$lines = file('https://api.facebook.com/method/links.getStats?urls='.$postUrl);

显示我使用以下内容的计数:

<div class="countNum"><?php echo $lines[6]; ?></div>

但现在$lines没有返回任何内容。

我也尝试了以下代码,但结果相同,没有显示任何内容。

$url11 = "http://api.facebook.com/restserver.php?method=links.getStats&urls=".$postUrl;
$xml = file_get_contents($url11);
$xml = simplexml_load_string($xml);
if(isset($_GET['check'])){
    var_dump($xml);
}

1 个答案:

答案 0 :(得分:0)

好吧我明白了。

$rest_url = "http://api.facebook.com/restserver.php?format=json&method=links.getStats&urls=".urlencode($url);

$json = json_decode(file_get_contents($rest_url),true);
echo '<p><span>'.$json[0]['share_count'].'</span> Shares</p>';


您也可以通过将'share_count'替换为
来获得其他计数 'LIKE_COUNT'
'COMMENT_COUNT'
'total_count'
'click_count'