skip to Main Content

I am getting a protected object returned from the API call to Facebook Ads.

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

I am getting the response like this :

    FacebookAdsObjectPage
          (
      [response:protected] => FacebookAdsHttpResponse Object
         (
            [response:protected] => Array
              (
                   [data] => Array
                        (
                             MY DATA
                        )
              )
    )
  )

I have already used used Reflection Class

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

and PtcHandyMan

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

but I am not able to access the protected property. Is there any way to access the protected property. And also I don’t get why facebook is giving the protected response.

This is my whole function

  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;
    }

2

Answers


  1. Try using getter methods for the property like getContent. This might get you access to the protected property.

    Login or Signup to reply.
  2. There are a lot ways to access the responses from facebook API.

    Your code:

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

    you are getting the response like this :

    FacebookAdsObjectPage
      (
        [response:protected] => FacebookAdsHttpResponse Object
           (
            [response:protected] => Array
              (
                [data] => Array
                  (MY DATA)
              )
          )
      )
    

    You can use asArray method

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

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

    or if you don’t want to use asArray use simple foreach for deeper levels:

    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
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search