try {
// Create a new AdAccount object with the Ad Account ID
$adAccount = new AdAccount($ad_account_id);
// Fetch ad sets (ad group IDs) for this ad account
$adsets = $adAccount->getAdSets([
'id', // Fetch Ad Set ID
'name', // Fetch Ad Set Name
'campaign_id' // Fetch Campaign ID (optional)
]);
// Loop through the results and print the Ad Set IDs
foreach ($adsets as $adset) {
echo 'Ad Set ID: ' . $adset['id'] . "\n";
echo 'Ad Set Name: ' . $adset['name'] . "\n";
echo 'Campaign ID: ' . $adset['campaign_id'] . "\n";
}
My goal is to fetch leads data
$app_id = 'YOUR_APP_ID'; $app_secret = 'YOUR_APP_SECRET'; $access_token = 'YOUR_ACCESS_TOKEN'; $ad_account_id = 'act_YOUR_AD_ACCOUNT_ID'; Api::init($app_id, $app_secret, $access_token);
// Optional: Enable curl logging to debug requests $api = Api::instance(); $api->setLogger(new CurlLogger());
try { // Create a new AdAccount object with the Ad Account ID $adAccount = new AdAccount($ad_account_id);
} catch (Exception $e) { // Handle error echo 'Error: ' . $e->getMessage(); }