2015-01-05 52 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 
    }