Facebook开发者路线图:弃用'评论'田野&删除'计算'来自'评论'

时间:2013-04-29 07:45:07

标签: facebook wordpress facebook-graph-api facebook-javascript-sdk

我注意到[FB开发者的新变化]:https://developers.facebook.com/roadmap/

我想知道您认为我需要在代码中进行更改。 我有wordpress,我有一个功能,可以计算评论的总数,当然它也需要在7月10日之后才能运作。

function full_comment_count() {
global $post;
$url = get_permalink($post->ID);

$filecontent = file_get_contents('https://graph.facebook.com/?ids=' . $url);
$json = json_decode($filecontent);
$count = $json->$url->comments;
$wpCount = get_comments_number();
$realCount = $count + $wpCount;
if ($realCount == 0 || !isset($realCount)) {
    $realCount = 0;
}
return $realCount;
} 

是否像改变一样简单:

$count

$total_count
在代码中还需要更改

或其他内容吗? 谢谢

1 个答案:

答案 0 :(得分:1)

Facebook路线图:

  

我们正在删除“评论”中未记录的“计数”字段   Graph API中的连接。请求   如果您想要摘要,请明确'{id} / comments?summary = true'   包含计数的字段(现在称为“total_count”)

... file_get_contents非常糟糕,CURL会更好,但更复杂。在这种情况下使用图形api的最佳方法是php sdk:https://github.com/facebook/facebook-php-sdk

无论如何,我想这些变化是必要的:

$filecontent = file_get_contents('https://graph.facebook.com/?ids=' . $url);

...这仍然是正确的,在此行之后(或在json解码之后)有一个var_dump,你会看到有一个“id”。使用该ID,您必须再次调用图api:

$comments= file_get_contents('https://graph.facebook.com/' . $id . '/comments?summary=true);

其余的是简单易用的基本php内容,只需在再次使用json_decode后执行var_dump $ comments。