2

Facebook広告へのAPI呼び出しから返される保護オブジェクトを取得しています。facebook ads apiのfacebookからの保護されたプロパティ応答へのアクセス方法

$page = new Page($page_id); 
$leadgen_forms = $page->getLeadgenForms(); 

私はこのような応答を取得しています:

FacebookAds\Object\Page 
      (
     [response:protected] => FacebookAds\Http\Response Object 
     (
      [response:protected] => Array 
       (
        [data] => Array 
         (
          MY DATA 
         ) 
      ) 
    ) 
) 

私は

$reflect=new \ReflectionClass($leadgen_forms); 
$properties=$reflect->getProperties('content'); 

PtcHandyMan

require_once('PtcHm.php'); 
PtcHandyMan::register(); 
$data = PtcHandyMan::getProperty($leadgen_forms , 'content'); 

使用Reflectionクラスをすでに使用しているが、私はできませんよ保護されたプロパティにアクセスします。保護されたプロパティにアクセスする方法はありますか?また、なぜfacebookが保護されたレスポンスを提供しているのか分からない。

これは私の全体の機能である

function get_page_forms(){ 
     if (!$this->input->is_ajax_request()) { 
      exit('No direct script access allowed'); 
     } 
     $page_id = $_POST['page_id']; 
     $page_access_token = $_POST['page_access_token']; 
     Api::init('APPID', 'SECRET KEY', $page_access_token); 
     $page = new Page($page_id); 
     $leadgen_forms = $page->getLeadgenForms(); 
     //$reflect=new \ReflectionClass($leadgen_forms); 
     //$properties=$reflect->getProperties('content'); 
     require_once('PtcHm.php'); 
     PtcHandyMan::register(); 
     $data = PtcHandyMan::getProperty($leadgen_forms , 'content'); 
     $allFormsArr = $data['data'];   
     $count = count($allFormsArr); 
     $output = '<div class="container"> 
        <table class="table table-responsive table-hover"> 
         <thead> 
          <tr> 
           <td>Id</td> 
           <td>Name</td> 
           <td>Leads csv file</td> 
           <td>Status</td> 
          </tr> 
         </thead> 
         <tbody>'; 
      for($i=0; $i<$count; $i++){ 
       $output .= '<tr> 
           <td>'.$allFormsArr[$i]['id'].'</td> 
           <td>'.$allFormsArr[$i]['name'].'</td> 
           <td><a href="'.$allFormsArr[$i]['leadgen_export_csv_url'].'" target="_new">Link</a></td> 
           <td>'.$allFormsArr[$i]['status'].'</td> 
          </tr>'; 
      } 
      $output .= '</tbody> 
        </table> 
       </div>'; 
     echo $output; 
    } 
+0

https://developers.facebook.com/docs/marketing-api/guides/lead-adsによると、 /forms-questions/v2.8#readingforms単純なデータ構造を取得する必要があります。そして、なぜそれが 'FacebookAds \ Object \ Page'と言うのですか?あなたがそこにダンプした' $ page'だけでなく、それがメソッドの戻り値だと確信していますか? – CBroe

+0

'FacebookAds \ Object \ Page'を無視します。私の主張は、保護されたデータへのアクセス方法です。ドキュメントでは単純なデータを示していますが、質問に表示されているように単純ではありません。 –

+0

結果として 'var_dump($ leadgen_forms);は何をしますか? – CBroe

答えて

0

FacebookのAPIから回答にアクセスする方法はたくさんあります。

あなたのコード:

$page = new Page($page_id); 
$leadgen_forms = $page->getLeadgenForms(); 

あなたがこのような応答になっています

FacebookAds\Object\Page 
     (
    [response:protected] => FacebookAds\Http\Response Object 
    (
     [response:protected] => Array 
      (
       [data] => Array 
        (
         MY DATA 
        ) 
     ) 
) 

)あなたはメソッドasArray使用することができます

$page = new Page($page_id); 
$leadgen_forms = $page->getLeadgenForms()->asArray(); 

https://developers.facebook.com/docs/php/GraphNode/5.0.0

か、asArrayは、より深いレベルのための簡単なforeachのを使用使用しない場合:

foreach ($leadgen_forms as $leadgen_form) { 
    heres your array. It may be protected so you might want to dig deeper with another foreach and so on 
} 
0

getContentのようなプロパティのゲッターメソッドを使用してみてください。これにより、保護されたプロパティにアクセスできるようになります。

+0

私もgetContentを使用しましたが、動作しませんでした –

関連する問題