2015-01-05 47 views
0

朋友,我无法处理返回呼叫的数据。我如何与数据交互,特别是附件。调用此链接的完整结果:http://pastebin.com/fLjV0Zu2处理帖子附件Facebook API SDK 4

我使用数组的转换方法,但似乎这种方法不会在对象的所有级别进行交互。所以我无法访问数据附件来处理。

$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

为什么不直接使用的对象,而不是。更好的方法来处理它 – WizKid

+0

你能给我一个如何与对象交互的例子吗? – SourceForge

+0

像这样'$ object-> subattachments' – WizKid

回答

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 
    }