繁体   English   中英

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

[英]Show facebook comment count in Joomla article blog view

注意:由于stackoverflow的严格规则,我在http://之后放置一个空格故意打破了我在这里发布的url。

如果您输入此网址

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

直接在浏览器中显示:

{“share”:{“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)显示NULL!

它出什么问题了 ? 有人可以帮忙吗? 谢谢

我不确定为什么以前的代码不起作用,但是有人向我建议了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;
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM