简体   繁体   中英

Loading custom audiences from facebook marketing api

According to this: https://developers.facebook.com/docs/marketing-api/reference/custom-audience#Reading the following piece of code should return the custom audiences related to my ads account. It does return an array of the objects, but the only fields populated on this is the ID (everything else, including its name, is null).

$account = new AdAccount(<ADS_ACCOUNT_NO>);
$audiences = $account->getCustomAudiences();

I've just found the answer and it is that you need to read() each object in order to obtain the full details.

Something like this should work fine:

$account = new AdAccount(<ADS_ACCOUNT_NO>);
$audiences = $account->getCustomAudiences();
$audiencesObjects = $audiences->getObjects();

foreach($audiencesObjects as $audienceObj) {
    $data = $audienceObj->read(['name', 'rule'])->getData();
    print $data['name'];
}

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