通过facebook api“喜欢”循环

Hey all i am trying to get all the likes for a wall post in PHP. The array frame looks like this:

Array ( 
[data] => Array ( 
    [0] => Array ( 
        [id] => XXXXXXXX_XXXXXXXXXXX 
        [from] => Array ( 
            [name] => Bob Barker
            [id] => XXXXXXXXXXX
        ) 
        [message] => This is a message here!!! 
        [story] => We shared a message with others
        [story_tags] => Array ( 
            [0] => Array ( 
                [0] => Array ( 
                    [id] => XXXXXXXXXX 
                    [name] => Bob Barker
                    [offset] => 0 
                    [length] => 11 
                    [type] => user 
                ) 
            ) 
            [19] => Array ( 
                [0] => Array ( 
                    [id] => XXXXXXXXXXXXXXXXXXXXXXX 
                    [name] => NAME 
                    [offset] => 19 
                    [length] => 5 
                    [type] => page 
                ) 
            ) 
        ) 
        [picture] => [removed] 
        [link] => [removed]
        [name] => Timeline Photos 
        [caption] => This is just a caption for the post here 
        [properties] => Array ( 
            [0] => Array ( 
                [name] => By 
                [text] => NAME 
                [href] => [removed] 
            ) 
        ) 
        [icon] => https://fbstatic-a.akamaihd.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif 
        [actions] => Array ( 
            [0] => Array ( 
                [name] => Like 
                [link] => [removed]
            ) 
        ) 
        [privacy] => Array ( 
            [value] => 
        ) 
        [type] => photo 
        [status_type] => shared_story 
        [object_id] => XXXXXXXXXXXXXXXX
        [application] => Array ( 
            [name] => Photos 
            [id] => XXXXXXXXXX 
        ) 
        [created_time] => 2014-02-12T21:33:17+0000 
        [updated_time] => 2014-02-12T21:33:17+0000 
        [likes] => Array ( 
            [data] => Array ( 
                [0] => Array ( 
                    [id] => XXXXXXXXXXXX 
                    [name] => John Doe 
                ) 
                [1] => Array ( 
                    [id] => XXXXXXXXXXXX 
                    [name] => Steve Doe 
                ) 
            ) 
            [paging] => Array ( 
                [cursors] => Array ( 
                    [after] => XXXXXXXXXXXXXXXX 
                    [before] => XXXXXXXXXXXX== 
                ) 
            ) 
        ) 
    ) 

My current PHP code is:

$feed = $facebook->api('/me/home'); //This is the array above

foreach($feed['data'] as $post) {
  $story = (isset($post['story']) ? $post['story'] : null);
  $id = (isset($post['id']) ? $post['id'] : null);
  $name = (isset($post['name']) ? $post['name'] : null);
  $message = (isset($post['message']) ? $post['message'] : null);
  $post_link = (isset($post['actions'][0]['link']) ? $post['actions'][0]['link'] : null);
  $picture = (isset($post['picture']) ? $post['picture'] : null);

  foreach($post['likes'] as $liked) {
      echo $post['id'];
  }

  echo $name . ' ' . $story . ' it was: ' . $message . ' and ' . $post_link .  ' and <img src="' . $picture . '" /><br />';
  echo '=======================================================================================================';
}

The

foreach($post['likes'] as $liked) {
      echo $post['id'];
}

doesnt seem to be working as-is. What am i missing in order to make it loop through all the "liked" posts in the array?

Yes

foreach($post['likes'] as $liked) {
      echo $post['id'];
}

will not work since

$post['likes'] elements are again a nested array as

likes => array => data => array=> ..

So you need to do the loop as

if(array_key_exists('data',$post['likes'])){
        foreach($post['likes']['data'] as $liked=>$val) {
            echo '<br />Like ID: ' .$val["id"].'<br />' ;
        }
    }

It is always better to do a check if the array key exists before doing the loop, so that if the returned data does not contain the key you do not get undefined index error.

Try

foreach($post['likes']->data as $like) {
  echo $like->id;
}