// we'll take the top result for now $target = count($results) ? $results->current() : null; echo "Using target: " . $target->name . "\n"; $targeting = new TargetingSpecs(); $targeting->{TargetingSpecsFields::GEO_LOCATIONS} = array('countries' => array('GB')); $targeting->{TargetingSpecsFields::INTERESTS} = array(array('id' => $target->id, 'name' => $target->name)); /** * Step 4 Create the AdSet */ use FacebookAds\Object\AdSet; use FacebookAds\Object\Fields\AdSetFields; use FacebookAds\Object\Values\OptimizationGoals; use FacebookAds\Object\Values\BillingEvents; $adset = new AdSet(null, $account->id); $adset->setData(array(AdSetFields::NAME => 'My First AdSet', AdSetFields::CAMPAIGN_GROUP_ID => $campaign->id, AdSetFields::CAMPAIGN_STATUS => AdSet::STATUS_ACTIVE, AdSetFields::DAILY_BUDGET => '150', AdSetFields::TARGETING => $targeting, AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::REACH, AdSetFields::BILLING_EVENT => BillingEvents::IMPRESSIONS, AdSetFields::BID_AMOUNT => 2, AdSetFields::START_TIME => (new \DateTime("+1 week"))->format(\DateTime::ISO8601), AdSetFields::END_TIME => (new \DateTime("+2 week"))->format(\DateTime::ISO8601))); $adset->validate()->create(); echo 'AdSet ID: ' . $adset->id . "\n"; /** * Step 5 Create an AdImage */ use FacebookAds\Object\AdImage; use FacebookAds\Object\Fields\AdImageFields; $image = new AdImage(null, $account->id); $image->{AdImageFields::FILENAME} = SDK_DIR . '/test/misc/image.png'; $image->create(); echo 'Image Hash: ' . $image->hash . "\n"; /** * Step 6 Create an AdCreative */ use FacebookAds\Object\AdCreative; use FacebookAds\Object\Fields\AdCreativeFields;
// we'll take the top result for now $target = count($results) ? $results->current() : null; echo "Using target: " . $target->name . "\n"; $targeting = new TargetingSpecs(); $targeting->{TargetingSpecsFields::GEO_LOCATIONS} = array('countries' => array('GB')); $targeting->{TargetingSpecsFields::INTERESTS} = array(array('id' => $target->id, 'name' => $target->name)); /** * Step 4 Create the AdSet */ use FacebookAds\Object\AdSet; use FacebookAds\Object\Fields\AdSetFields; use FacebookAds\Object\Values\OptimizationGoals; use FacebookAds\Object\Values\BillingEvents; $adset = new AdSet(null, $account->id); $adset->setData(array(AdSetFields::NAME => 'My First AdSet', AdSetFields::CAMPAIGN_ID => $campaign->id, AdSetFields::DAILY_BUDGET => '150', AdSetFields::TARGETING => $targeting, AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::REACH, AdSetFields::BILLING_EVENT => BillingEvents::IMPRESSIONS, AdSetFields::BID_AMOUNT => 100, AdSetFields::START_TIME => (new \DateTime("+1 week"))->format(\DateTime::ISO8601), AdSetFields::END_TIME => (new \DateTime("+2 week"))->format(\DateTime::ISO8601))); $adset->validate()->create(array(AdSet::STATUS_PARAM_NAME => AdSet::STATUS_ACTIVE)); echo 'AdSet ID: ' . $adset->id . "\n"; /** * Step 5 Create an AdImage */ use FacebookAds\Object\AdImage; use FacebookAds\Object\Fields\AdImageFields; $image = new AdImage(null, $account->id); $image->{AdImageFields::FILENAME} = SDK_DIR . '/test/misc/image.png'; $image->create(); echo 'Image Hash: ' . $image->hash . "\n"; /** * Step 6 Create an AdCreative */ use FacebookAds\Object\AdCreative; use FacebookAds\Object\Fields\AdCreativeFields;