skip to Main Content

I am working on the facebook ads API (3.2) But I am getting some weird errors. I am trying to get the campaigns And following is the method I am using for this according to the documentation Here

public function getcampaigns() {
   $adaccount = new AdAccount('331*****10774');
   $campaigns = $adaccount->getCampaigns();
   print_r($campaigns);
}

But I am getting the error
enter image description here

Then I try this with Explorer with the same access_token and it worked well.
enter image description here

I am giving the following permissions in access_token

$this->permissions = ['email', 'ads_management', 'pages_show_list', 'publish_pages', 'manage_pages', 'ads_read', 'business_management'];

2

Answers


  1. You need to get your APP approved by Facebook to access the permission ads_management

    It will work on explorer since it’s just a tool FB has provided to test and play around.

    Login or Signup to reply.
  2. You should prefix with the act_ string, so

    try this:

       $adaccount = new AdAccount('act_331*****10774');
    

    instead of this:

       $adaccount = new AdAccount('331*****10774');
    

    In addition, if you test the example:

    use FacebookAdsObjectAdAccount;
    use FacebookAdsApi;
    use FacebookAdsLoggerCurlLogger;
    
    $id = 'act_XXXX';
    
    $api = Api::init($app_id, $app_secret, $access_token);
    $api->setLogger(new CurlLogger());
    
    $fields = array(
      'name',
      'objective',
    );
    $params = array(
      'effective_status' => array('ACTIVE','PAUSED'),
    );
    echo json_encode((new AdAccount($id))->getCampaigns(
      $fields,
      $params
    )->getResponse()->getContent(), JSON_PRETTY_PRINT);
    

    Works as expected

    Hope this help

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search