public function setup() { parent::setup(); $this->adCampaign = new AdCampaign(null, $this->getActId()); $this->adCampaign->{AdCampaignFields::NAME} = $this->getTestRunId(); $this->adCampaign->create(); $this->adSet = new AdSet(null, $this->getActId()); $this->adSet->{AdSetFields::CAMPAIGN_GROUP_ID} = (int) $this->adCampaign->{AdSetFields::ID}; $this->adSet->{AdSetFields::NAME} = $this->getTestRunId(); $this->adSet->{AdSetFields::CAMPAIGN_STATUS} = AdSet::STATUS_PAUSED; $this->adSet->{AdSetFields::DAILY_BUDGET} = '150'; $this->adSet->{AdSetFields::START_TIME} = (new \DateTime("+1 week"))->format(\DateTime::ISO8601); $this->adSet->{AdSetFields::END_TIME} = (new \DateTime("+2 week"))->format(\DateTime::ISO8601); $this->adSet->create(); $this->adImage = new AdImage(null, $this->getActId()); $this->adImage->{AdImageFields::FILENAME} = $this->getTestImagePath(); $this->adImage->save(); $this->adCreative = new AdCreative(null, $this->getActId()); $this->adCreative->{AdCreativeFields::TITLE} = 'My Test Ad'; $this->adCreative->{AdCreativeFields::BODY} = 'My Test Ad Body'; $this->adCreative->{AdCreativeFields::OBJECT_ID} = $this->getPageId(); $this->adCreative->{AdCreativeFields::IMAGE_HASH} = $this->adImage->{AdImageFields::HASH}; $this->adCreative->create(); $targeting = new TargetingSpecs(); $targeting->{TargetingSpecsFields::GEO_LOCATIONS} = array('countries' => array('US')); $this->adGroup = new AdGroup(null, $this->getActId()); $this->adGroup->{AdGroupFields::ADGROUP_STATUS} = AdGroup::STATUS_PAUSED; $this->adGroup->{AdGroupFields::NAME} = $this->getTestRunId(); $this->adGroup->{AdGroupFields::BID_TYPE} = AdGroup::BID_TYPE_CPM; $this->adGroup->{AdGroupFields::BID_INFO} = array(AdGroupBidInfoFields::IMPRESSIONS => '2'); $this->adGroup->{AdGroupFields::CAMPAIGN_ID} = (int) $this->adSet->{AdSetFields::ID}; $this->adGroup->{AdGroupFields::TARGETING} = $targeting; $this->adGroup->{AdGroupFields::CREATIVE} = array('creative_id' => $this->adCreative->{AdCreativeFields::ID}); $this->adGroup->create(); }
public function setup() { parent::setup(); $targeting = new TargetingSpecs(); $targeting->{TargetingSpecsFields::GEO_LOCATIONS} = array('countries' => array('US')); $this->campaign = new Campaign(null, $this->getConfig()->accountId); $this->campaign->{CampaignFields::NAME} = $this->getConfig()->testRunId; $this->campaign->create(); $this->adSet = new AdSet(null, $this->getConfig()->accountId); $this->adSet->{AdSetFields::CAMPAIGN_ID} = (int) $this->campaign->{AdSetFields::ID}; $this->adSet->{AdSetFields::NAME} = $this->getConfig()->testRunId; $this->adSet->{AdSetFields::DAILY_BUDGET} = '150'; $this->adSet->{AdSetFields::START_TIME} = (new \DateTime("+1 week"))->format(\DateTime::ISO8601); $this->adSet->{AdSetFields::END_TIME} = (new \DateTime("+2 week"))->format(\DateTime::ISO8601); $this->adSet->{AdFields::TARGETING} = $targeting; $this->adSet->{AdSetFields::OPTIMIZATION_GOAL} = OptimizationGoals::REACH; $this->adSet->{AdSetFields::BILLING_EVENT} = BillingEvents::IMPRESSIONS; $this->adSet->{AdSetFields::BID_AMOUNT} = 2; $this->adSet->create(array(AdSet::STATUS_PARAM_NAME => AdSet::STATUS_PAUSED)); $this->adImage = new AdImage(null, $this->getConfig()->accountId); $this->adImage->{AdImageFields::FILENAME} = $this->getConfig()->testImagePath; $this->adImage->save(); $this->adCreative = new AdCreative(null, $this->getConfig()->accountId); $this->adCreative->{AdCreativeFields::TITLE} = 'My Test Ad'; $this->adCreative->{AdCreativeFields::BODY} = 'My Test Ad Body'; $this->adCreative->{AdCreativeFields::OBJECT_ID} = $this->getConfig()->pageId; $this->adCreative->{AdCreativeFields::IMAGE_HASH} = $this->adImage->{AdImageFields::HASH}; $this->adCreative->create(); $this->ad = new Ad(null, $this->getConfig()->accountId); $this->ad->{AdFields::NAME} = $this->getConfig()->testRunId; $this->ad->{AdFields::ADSET_ID} = (int) $this->adSet->{AdSetFields::ID}; $this->ad->{AdFields::CREATIVE} = array('creative_id' => $this->adCreative->{AdCreativeFields::ID}); $this->ad->create(array(Ad::STATUS_PARAM_NAME => Ad::STATUS_PAUSED)); }
private function createAdSet($campaignId) { $adset = new AdSet(null, 'act_' . $this->adAccountId); $adset->setData(array(AdSetFields::NAME => 'My Ad Set ' . date("Y-m-d H:i:s"), AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::REACH, AdSetFields::BILLING_EVENT => BillingEvents::IMPRESSIONS, AdSetFields::BID_AMOUNT => 20, AdSetFields::DAILY_BUDGET => 1000, AdSetFields::CAMPAIGN_ID => $campaignId, AdSetFields::TARGETING => (new TargetingSpecs())->setData(array(TargetingSpecsFields::GEO_LOCATIONS => array('countries' => array('US')))))); $adset->create(array(AdSet::STATUS_PARAM_NAME => AdSet::STATUS_PAUSED)); return $adset->getData()[AdSet::FIELD_ID]; }
use FacebookAds\Object\AdCampaign; use FacebookAds\Object\Fields\AdCampaignFields; use FacebookAds\Object\Values\AdObjectives; use FacebookAds\Object\Values\AdBuyingTypes; $campaign = new AdCampaign(null, $account->id); $campaign->setData(array(AdCampaignFields::NAME => 'My First Campaign', AdCampaignFields::OBJECTIVE => AdObjectives::WEBSITE_CLICKS, AdCampaignFields::STATUS => AdCampaign::STATUS_PAUSED)); $campaign->create(); echo "Campaign ID:" . $campaign->id . "\n"; /** * Step 3 Create the AdSet */ use FacebookAds\Object\AdSet; use FacebookAds\Object\Fields\AdSetFields; $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::START_TIME => (new \DateTime("+1 week"))->format(\DateTime::ISO8601), AdSetFields::END_TIME => (new \DateTime("+2 week"))->format(\DateTime::ISO8601))); $adset->create(); echo 'AdSet ID: ' . $adset->id . "\n"; /** * Step 4 Create an AdImage */ use FacebookAds\Object\AdImage; use FacebookAds\Object\Fields\AdImageFields; $image = new AdImage(null, $account->id); $image->filename = SDK_DIR . '/test/misc/FB-f-Logo__blue_512.png'; $image->create(); echo 'Image Hash: ' . $image->hash . "\n"; /** * Step 5 Create an AdCreative */ use FacebookAds\Object\AdCreative; use FacebookAds\Object\Fields\AdCreativeFields;