简体   繁体   中英

Show facebook comment count in Joomla article blog view

NOTE : the url I posted here was purposely broken by putting a space after the http:// due to the strict rules of stackoverflow.

If you enter this url

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

directly in browser, it displays :

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

Fine. So I prepare the php as follow :

<?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;
?>

It display nothing at all. I tried var_dump($obj) display NULL !!

What's wrong with it ? Can someone help please ? thanks

I am not sure why the previous code not working, but someone had suggested to me the CURL, which is working :-

<?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;
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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