1

我正在尝试在用户喜欢的字段名称上创建一个 for each 循环。问题是我只得到错误或根本没有结果。有人可以告诉我解析这些数据的正确方法吗?

我正在尝试从以下代码中获取该字段:

   {
   "data": [
      {
         "category": "Tv show",
         "name": "South Park",
         "id": "6708787004",
         "created_time": "2013-05-19T14:53:15+0000"
      },
      {
         "category": "Tv show",
         "name": "Futurama",
         "id": "9588466619",
         "created_time": "2013-05-19T14:53:03+0000"
      },
      {
         "category": "Product/service",
         "name": "ROCK ZOTTEGEM",
         "id": "79367311142",
         "created_time": "2013-05-06T15:23:41+0000"
      },
      {
         "category": "Musician/band",
         "name": "netsky",
         "id": "85506412028",
         "created_time": "2013-05-06T15:21:24+0000"
      },
      {
         "category": "Media/news/publishing",
         "name": "Tasty Network",
         "id": "186383034758939",
         "created_time": "2013-05-06T15:21:10+0000"
      },
      {
         "category": "Musician/band",
         "name": "UKF Drum & Bass",
         "id": "274197690441",
         "created_time": "2013-05-06T15:20:25+0000"
      },
      {
         "category": "Musician/band",
         "name": "Savant",
         "id": "204538756277738",
         "created_time": "2013-05-06T15:20:04+0000"
      }
   ],
   "paging": {
      "next": "https://graph.facebook.com/100005892006494/likes?access_token=AWfibl9UD01FGmIlwGPABZArZBucGjBZBp2XMt1fj3X5f3uHNvZBhPMqjHyXc6NZB8t0EcGOkTY9KcZBEZAbbuSnwrFqVNhvQl0MOuqqAlDsr8geNezi6IOGAsI64VnlHEY9rLZAK8y0WbgZDZD&limit=5000&offset=5000&__after_id=204538756277738"
   }
}

我的PHP代码是:

$facebookRequest="https://graph.facebook.com/".$user."/likes?access_token=".$access_token."";
   $likes = json_decode(file_get_contents($facebookRequest));
   //$requests = file_get_contents($facebookRequest);

            //print_r($likes);

            foreach($likes as $like => $item)
        {
            echo $item->name;
        }
4

1 回答 1

1

您需要访问该数组dataname从它的每个子项中获取该字段。您当前正在做的是尝试name从不存在的数组中获取字段。

尝试改变这个:

foreach($likes as $like => $item)

对此:

foreach($likes->data as $like => $item)
于 2013-05-20T07:48:36.737 回答