Facebook Graph API使用PHP解析JSON提要

Tif*_*ael 7 php json facebook facebook-graph-api

我试图使用PHP来解析使用Facebook Graph API的帖子的JSON提要

我发现以下解决方案的评论......

<?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 />';
    }
  }
} 
    ?>
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的网址:https://graph.facebook.com/210849652406/feed/ access_token = {VALID_USER_TOKEN}

我只是不知道如何调用此Feed的项目.我试图用这个帖子/提要来解析评论,但我基本上什么都没有.我想要基本的项目,如帖子的名称,标题等.我想如果我能得到帖子的名字,我可以把它弄清楚!

Som*_*jee 7

你循环不正确

试试这个

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 />';
}
Run Code Online (Sandbox Code Playgroud)