Facebook响应中的数据解析错误

时间:2017-01-02 09:49:36

标签: php json facebook facebook-graph-api

我正在尝试在最新的facebook api中获取朋友个人资料照片。

$request1 = new FacebookRequest( $session, 'GET', '/me/invitable_friends?fields=id,name,picture.type(normal)&limit=5' );
  $response1 = $request1->execute();

  $graphObject1 = $response1->getGraphObject();
  $fname = $graphObject1->AsArray();

我收到了这个回复

array(5){  
   [  
      0
   ]   => object(stdClass)#13 (3)   {  
      [  
         "id"
      ]      => string(110) "AVlkiLpj2OrXVjBe2xqHHpZHmVx8WedF28ZakdPf5ixuiRbBh1gmT0AELmxpFFbKazQmajZTbHVOCQn4PTkhyYsAEYm2wY2zma76LKNgAzixUA"      [  
         "name"
      ]      => string(18) "Shivnarayan Jangid"      [  
         "picture"
      ]      => object(stdClass)#14 (1)      {  
         [  
            "data"
         ]         => object(stdClass)#15 (2)         {  
            [  
               "is_silhouette"
            ]            => bool(false)            [  
               "url"
            ]            => string(208) "https://fb-s-c-a.akamaihd.net/h-ak-xal1/v/t1.0-1/p100x100/12316239_849133168517451_5573830579729777887_n.jpg?oh=381a001796f172460edb1c12978c238c&oe=58E447AA&__gda__=1495195363_4166d52205da017e520efe2c8f82903e"
         }
      }
   }   [  
      1
   ]   => object(stdClass)#16 (3)   {  
      [  
         "id"
      ]      => string(110) "AVnm3bQQ_mEuMO-g42H2XrenRK29xWkYHoWofvSo_Yn_XFiNjTXKHAQ6Csw6aW-yYmm_qpxsYmi39daIXDavdGkG9xmdc5Y2f270Vs8Hc4LyPQ"      [  
         "name"
      ]      => string(12) "Sameer Katwe"      [  
         "picture"
      ]      => object(stdClass)#17 (1)      {  
         [  
            "data"
         ]         => object(stdClass)#18 (2)         {  
            [  
               "is_silhouette"
            ]            => bool(false)            [  
               "url"
            ]            => string(208) "https://fb-s-a-a.akamaihd.net/h-ak-xfp1/v/t1.0-1/p100x100/14910502_950715611701314_5931625519981925021_n.jpg?oh=62ad41fdda91148c2ddb090c97458eec&oe=58DCE0BB&__gda__=1490455729_314dd8295133cdd14c5103b39475e0bb"
         }
      }
   }   [  
      2
   ]   => object(stdClass)#19 (3)   {  
      [  
         "id"
      ]      => string(110) "AVnEvaz_3htMOQeXHdzUZfacq1CjJvVVOFWFJEw9s5rx4FORE6rSQZsJFrsrSWtjh_F6v6mxGheEksHvIjDbDHxye7Juu9l_IvqpAM4nFJQbbA"      [  
         "name"
      ]      => string(13) "Leethan Rohit"      [  
         "picture"
      ]      => object(stdClass)#20 (1)      {  
         [  
            "data"
         ]         => object(stdClass)#21 (2)         {  
            [  
               "is_silhouette"
            ]            => bool(false)            [  
               "url"
            ]            => string(205) "https://fb-s-c-a.akamaihd.net/h-ak-xap1/v/t1.0-1/s100x100/65527_322856177899716_8103687485969238374_n.jpg?oh=e4a04c8684a5b81164d6c75847c2ad04&oe=58E2E797&__gda__=1490586919_6cfa9ebe2ee48ce330dca69c6649c243"
         }
      }
   }   [  
      3
   ]   => object(stdClass)#22 (3)   {  
      [  
         "id"
      ]      => string(110) "AVnOxJCFtbRoQrG29sslnNU86Svf0UdFJqgbEtiwDxpLn6UusccSfkoYXBVMjwSFesJeQ2ZjIxAKO_cto0Rk3TQEjNv3HNs-DvvD8oOTHBlKSw"      [  
         "name"
      ]      => string(12) "Neelam Katwe"      [  
         "picture"
      ]      => object(stdClass)#23 (1)      {  
         [  
            "data"
         ]         => object(stdClass)#24 (2)         {  
            [  
               "is_silhouette"
            ]            => bool(false)            [  
               "url"
            ]            => string(209) "https://fb-s-b-a.akamaihd.net/h-ak-xlp1/v/t1.0-1/p100x100/15740997_1283628385045517_1812997983243581871_n.jpg?oh=996b081ccd71dedd089c3962fa5b8601&oe=59204A2D&__gda__=1491618514_28f82c5503155a427524335c5bc13fd8"
         }
      }
   }   [  
      4
   ]   => object(stdClass)#25 (3)   {  
      [  
         "id"
      ]      => string(110) "AVkWJI3EDTVLMguVpWETaOU6OzZpKOySJ9Gi9xtUuPMeSYxoLzu6JQLYE3H-sqKcpM9Ryu6xEvVSh_yFGUT57Q6Xu8zLAmaxx4Om4V9Hu2CEdA"      [  
         "name"
      ]      => string(11) "Divya Gupta"      [  
         "picture"
      ]      => object(stdClass)#26 (1)      {  
         [  
            "data"
         ]         => object(stdClass)#27 (2)         {  
            [  
               "is_silhouette"
            ]            => bool(false)            [  
               "url"
            ]            => string(209) "https://fb-s-c-a.akamaihd.net/h-ak-xtp1/v/t1.0-1/p100x100/14212681_1091771700909665_1239783294366264056_n.jpg?oh=93e82a4f8a6d07acefea89db90ecf5de&oe=58E6B605&__gda__=1491009063_4737ca28022c4613d8f1d776eddcd5ae"
         }
      }
   }
}object(stdClass)#28 (2){  
   [  
      "cursors"
   ]   => object(stdClass)#29 (2)   {  
      [  
         "before"
      ]      => string(124) "QVFIUjdFbG0wNXVBZAm5NSU5Xdkt4VmRDaXIwR2Jxcjc3YXNNUGNaRVJkTnlOMUlraUw1VVhTTkhHVEhRX3ZAEMW9uLVo5alNoU0hJeWJWajZAQMEZAVeEo1R3dB"      [  
         "after"
      ]      => string(122) "QVFIUlFNMmV5YVZABU3JKTUZApOW82Q0dtSzdmd3FpN2p2d085SE1hbEI1bEo5UVFmV25TTEpJNmVVbGp3RllKYjhpWndTeHpObWdWcWdjSVR5cEptVENmUTN3"
   }   [  
      "next"
   ]   => string(439) "https://graph.facebook.com/v2.8/1871548009745987/invitable_friends?access_token=EAAFOxTjmzpIBANWIalY14b1zJJi38C49OdQyz1sjwtrY39dLHRhDsS0rd0ZAYiLEkSZAGBee3pedid5vc7cI7wSNWewsZBLqKI6QP8WHGaSw7BoJ08FEWnl9x4VX9ZCPXGzvZBqvbYReZCuPT4OWHFWRQLZCoW3m44zoWQK0xgS8QZDZD&fields=id%2Cname%2Cpicture.type%28normal%29&limit=5&after=QVFIUlFNMmV5YVZABU3JKTUZApOW82Q0dtSzdmd3FpN2p2d085SE1hbEI1bEo5UVFmV25TTEpJNmVVbGp3RllKYjhpWndTeHpObWdWcWdjSVR5cEptVENmUTN3"
}

我正在尝试选择朋友个人资料照片和他的名字作为变量

$friendpic = $friends['data'][0]['picture']['data']['url'];
$friendpic1 = $friends['data'][1]['picture']['data']['url'];
$friendpic2 = $friends['data'][2]['picture']['data']['url'];
$friendpic3 = $friends['data'][3]['picture']['data']['url'];  

如何将这个新的api响应解析为单个变量。

感谢。

0 个答案:

没有答案