在Joomla文章博客视图中显示Facebook评论计数


Show facebook comment count in Joomla article blog view

注意:由于堆栈溢出的严格规则,我在这里发布的网址是在 http://后放置空格故意破坏的。

如果您输入此网址

https://graph.facebook.com/v2.4/?fields=share{comment_count}&id=http://kclau.com/investment/where-klci-is-heading/

直接在浏览器中,它显示:

{ "共享": { "comment_count": 3 }, "id": "http://kclau.com/investment/where-klci-is-heading/" }

好。所以我准备了如下的php:

<?php 
$url = "http:// kclau.com/investment/where-klci-is-heading/";
$response = file_get_contents("https:// graph.facebook.com/v2.4/?fields=share{comment_count}&id=".$url);
$obj = json_decode($response);
echo $obj->share->comment_count;
?>

它根本不显示任何内容。我尝试var_dump($obj)显示空!

怎么了?有人可以帮忙吗?谢谢

我不确定为什么以前的代码不起作用,但有人向我建议了 CURL,它正在工作:-

<?php
$url = "http://kclau.com/investment/where-klci-is-heading/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/v2.4/?fields=share{comment_count}&id=".$url);
$result = curl_exec($ch);
curl_close($ch);
$obj = json_decode($result);
echo $obj->share->comment_count;
?>