简体   繁体   中英

Facebook Business SDK PHP - Cannot Fetch Campaign Fields

I am trying to get the campaign names of an ad account with the following code

$account = new AdAccount($account_id);
$cursor = $account->getCampaigns();
echo sizeof($cursor);

// Loop over objects
foreach ($cursor as $campaign) {
    echo $campaign->{CampaignFields::NAME}.PHP_EOL;
}

The cursor has the correct number of campaigns but I get empty field values. Same applies when I try to get the Ad Account fields.

Does anybody know why is this happening? I am using the latest version of API (v5.0)

Thanks in advance.

You should add the field you want to request by the API in the method, as example:

$cursor = $account->getCampaigns(['id','name']);

Refer also to the AdAccountsCampaigns example for further details about the usage of fields and params :

$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);

Hope this help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM