2015-01-05 6 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가 내 아이디어를 삭제했습니다.

페이스 북의 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 
    }