Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Graph API parse JSON feed with PHP

I am trying to use php to parse a JSON feed of posts using Facebook Graph API

I found the following solution for comments...

<?php 

$request_url ="https://graph.facebook.com/comments/?

ids=http://www.youtube.com/watch?v=fyF-fj-1coY&feature=player_embedded";
$requests = file_get_contents($request_url);

$fb_response = json_decode($requests);




foreach ($fb_response as $key => $response) {
  foreach ($fb_response->$key as $data) {
    foreach ($data as $item) {
      echo 'NAME: ' . $item->name . '<br />';
      echo 'From ID: ' . $item->from->id . '<br />';
      echo 'From Name: ' . $item->from->name . '<br />';
      echo 'Message: ' . $item->message . '<br />';
      echo 'Timestamp: ' . $item->created_time . '<br /><br />';
    }
  }
} 
    ?>

This is the url id I'm working with: https://graph.facebook.com/210849652406/feed/?access_token={VALID_USER_TOKEN}

I just don't know how to call the items for this feed. I'm trying to make the comments parse with this post/feed but I get essentially nothing. I want the basic items like name of the post, caption, etc. I think if I just could get the name of the post I could figure it all out!

like image 793
Tiffany Israel Avatar asked Feb 03 '12 19:02

Tiffany Israel


1 Answers

You are looping incorrectly

try this

foreach($fb_response->data as $item){
echo 'Message: ' . $item->message . '<br />';//there is no name returned on a comment
echo 'From ID: ' . $item->from->id . '<br />';
 echo 'From Name: ' . $item->from->name . '<br />';
 echo 'Message: ' . $item->message . '<br />';
 echo 'Timestamp: ' . $item->created_time . '<br /><br />';
}
like image 146
SoWhat Avatar answered Nov 19 '22 19:11

SoWhat