Facebook ads API : Object with ID '***********

2019-08-07 08:50发布

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条回答
ゆ 、 Hurt°
2楼-- · 2019-08-07 09:25

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.

查看更多
Deceive 欺骗
3楼-- · 2019-08-07 09:27

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 FacebookAds\Object\AdAccount;
use FacebookAds\Api;
use FacebookAds\Logger\CurlLogger;

$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

查看更多
登录 后发表回答