输出脸书网址评论json_decode



我正在尝试用PHP输出Facebook页面的评论。例如:

http://graph.facebook.com/comments/?ids=http://www.example.com

有人可以解释如何正确解码它,以便我可以将所有评论显示在页面上吗?

我已经尝试了几个不同的脚本/扩展,但它们似乎都没有返回任何结果或错误,所以我认为图形 API 可能已经发生了变化。

    //get the json string from URL
        $data = file_get_contents("http://www.example.com");
        //transform json to associative array
        $data = json_decode($data, true);
        //use only the comments array
        $comments = $data['http://www.example.com']['comments']['data'];
        foreach($comments as $comment) { 
            echo $comment['from']['name'];
            echo $comment['message'];
        }
//get the json string from URL
$data = file_get_contents("http://graph.facebook.com/comments/?ids=http://www.example.com");
//transform json to associative array
$data = json_decode($data, true);
//use only the comments array
$comments = $data['http://www.example.com']['comments']['data'];
//you should only see the comments array printed
echo "<pre>"; print_r($comments); echo "</pre>";

最新更新