-1

我正在尝试在 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'];
        }
4

1 回答 1

3
//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>";
于 2012-06-26T05:40:35.460 回答