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->{AdSetFields::TARGETING} = $targeting; $this->adSet->{AdSetFields::OPTIMIZATION_GOAL} = OptimizationGoals::REACH; $this->adSet->{AdSetFields::BILLING_EVENT} = BillingEvents::IMPRESSIONS; $this->adSet->{AdSetFields::BID_AMOUNT} = 2; $this->adSet->save(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(); $link = new LinkData(); $link->{LinkDataFields::MESSAGE} = 'Message'; $link->{LinkDataFields::IMAGE_HASH} = $this->adImage->{AdImageFields::HASH}; $link->{LinkDataFields::LINK} = $this->getConfig()->appUrl; $story = new ObjectStorySpec(); $story->{ObjectStorySpecFields::PAGE_ID} = $this->getConfig()->pageId; $story->{ObjectStorySpecFields::LINK_DATA} = $link; $this->adCreative = new AdCreative(null, $this->getConfig()->accountId); $this->adCreative->{AdCreativeFields::OBJECT_STORY_SPEC} = $story; $this->adCreative->create(); }
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 createAdCreateive($postId) { $creative = new AdCreative(null, 'act_' . $this->adAccountId); $creative->setData(array(AdCreativeFields::NAME => 'Sample Promoted Post ' . date("Y-m-d H:i:s"), AdCreativeFields::OBJECT_STORY_ID => $this->pageId . '_' . $postId)); $creative->create(); return $creative->getData()[AdCreative::FIELD_ID]; }
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->save(); $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->create(); }
$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; $creative = new AdCreative(null, $account->id); $creative->setData(array(AdCreativeFields::NAME => 'Sample Creative', AdCreativeFields::TITLE => 'Welcome to the Jungle', AdCreativeFields::BODY => 'We\'ve got fun \'n\' games', AdCreativeFields::IMAGE_HASH => $image->hash, AdCreativeFields::OBJECT_URL => 'http://www.example.com/')); $creative->create(); echo 'Creative ID: ' . $creative->id . "\n"; /** * Step 7 Create an AdGroup */ use FacebookAds\Object\AdGroup; use FacebookAds\Object\Fields\AdGroupFields; $adgroup = new AdGroup(null, $account->id); $adgroup->setData(array(AdGroupFields::CREATIVE => array('creative_id' => $creative->id), AdGroupFields::NAME => 'My First AdGroup', AdGroupFields::CAMPAIGN_ID => $adset->id)); $adgroup->create(); echo 'AdGroup ID:' . $adgroup->id . "\n";