I am trying to output the comments of a facebook page in PHP. For example:
http://graph.facebook.com/comments/?ids=http://www.example.com
Can someone please explain how to decode this correctly so I can have all comments appearing on a page?
I have tried a couple of different scripts/expamples but they all seem to be returning no results or an error, so i think maybe the graph API has changed since.
//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'];
}
1 Answer