How to list custom audiences via facebook api?
@priscilla.langworth
To list custom audiences via the Facebook API, you can follow these steps:
Here's an example using the Facebook Graph API in PHP:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
<?php require_once 'path-to-facebook-sdk/autoload.php'; use FacebookAdsApi; use FacebookAdsObjectAdAccount; use FacebookAdsObjectFieldsCustomAudienceFields; // Initialize the Facebook API Api::init('<app_id>', '<app_secret>', '<access_token>'); // Get the Ad Account object $adAccount = new AdAccount('<ad_account_id>'); // Retrieve the custom audiences $customAudiences = $adAccount->getCustomAudiences(array( CustomAudienceFields::NAME, CustomAudienceFields::ID )); // Print the list of custom audiences foreach ($customAudiences as $audience) { echo $audience->{CustomAudienceFields::ID}. ': '; echo $audience->{CustomAudienceFields::NAME}. ' '; } ?> |
Make sure to replace <app_id>
, <app_secret>
, <access_token>
, and <ad_account_id>
with your specific values.
With this code, you should be able to retrieve and list the custom audiences associated with your Facebook account using the Facebook API.