朋友,我无法处理返回通话的数据。我如何与数据交互,特别是与附件交互。调用此链接的完整结果:http://pastebin.com/fLjV0Zu2
我正在使用数组的转换方法,但似乎此方法不会在对象的所有级别上进行交互。所以我无法访问要处理的数据附件。
$graphObject = $response->getGraphObject()->asArray();
$media = $graphObject->getProperty('attachments')->asArray();
print_r($media);
结果:
Array
(
[0] => stdClass Object
(
[subattachments] => stdClass Object
(
[data] => Array
(
[0] => stdClass Object
(
[media] => stdClass Object
(
[image] => stdClass Object
(
[height] => 483
[src] => https://scontent-a.xx.fbcdn.net/hphotos-xpa1/v/t1.0-9/s720x720/10891987_811524088885970_7055896286836804482_n.jpg?oh=895cce48d5da3e59b374fad2f7ec8f69&oe=55297847
[width] => 720
)
)
[target] => stdClass Object
(
[id] => 811524088885970
[url] => https://www.facebook.com/photo.php?fbid=811524088885970&set=gm.767232516689804&type=1
)
[type] => photo
[url] => https://www.facebook.com/photo.php?fbid=811524088885970&set=gm.767232516689804&type=1
)
[1] => stdClass Object
(
[media] => stdClass Object
(
[image] => stdClass Object
(
[height] => 404
[src] => https://scontent-a.xx.fbcdn.net/hphotos-xaf1/v/t1.0-9/s720x720/10885099_811524235552622_234704175575422999_n.jpg?oh=d94c5f69852665adb5a8bae2217cc900&oe=552A30F4
[width] => 720
)
)
[target] => stdClass Object
(
[id] => 811524235552622
[url] => https://www.facebook.com/photo.php?fbid=811524235552622&set=gm.767232516689804&type=1
)
[type] => photo
[url] => https://www.facebook.com/photo.php?fbid=811524235552622&set=gm.767232516689804&type=1
)
[2] => stdClass Object
(
[media] => stdClass Object
(
[image] => stdClass Object
(
[height] => 404
[src] => https://scontent-b.xx.fbcdn.net/hphotos-xap1/v/t1.0-9/s720x720/10898031_811524285552617_7673546158326216312_n.jpg?oh=3376e9140822a7a79904f58f30214c5d&oe=552D6772
[width] => 720
)
)
[target] => stdClass Object
(
[id] => 811524285552617
[url] => https://www.facebook.com/photo.php?fbid=811524285552617&set=gm.767232516689804&type=1
)
[type] => photo
[url] => https://www.facebook.com/photo.php?fbid=811524285552617&set=gm.767232516689804&type=1
)
)
)
[target] => stdClass Object
(
[id] => 767232516689804
[url] => https://www.facebook.com/media/set/?set=pcb.767232516689804&type=1
)
[title] => Photos from Conceicao Fernandes's post
[type] => album
[url] => https://www.facebook.com/media/set/?set=pcb.767232516689804&type=1
)
)
答案 0 :(得分:0)
对于那些有同样问题的人。或者更确切地说是怀疑。
朋友WizKid清除了我的想法。
即使使用正确的方法使用Facebook PHP SDK4转换GraphObject的结果,调用asArray();
来访问数据,我也成功使用了以下表格。
$media = $graphObject->getProperty('attachments')->asArray();
$media[0]->subattachments->data;
使用foreach()
$data = $media[0]->subattachments->data;
foreach($data as $k => $v) {
//Here you interacted with the data
}