public function tearDown() { if ($this->adSet) { $this->adSet->delete(); $this->adSet = null; } if ($this->adCampaign) { $this->adCampaign->delete(); $this->adCampaign = null; } if ($this->adCreative) { $this->adCreative->delete(); $this->adCreative = null; } if ($this->adImage) { $this->adImage->delete(); $this->adImage = null; } parent::tearDown(); }
public function testDynamicProductAdsCreation() { $this->adCampaign = new AdCampaign(null, $this->getConfig()->accountId); $this->adCampaign->setData(array(AdCampaignFields::NAME => $this->getConfig()->testRunId, AdCampaignFields::OBJECTIVE => AdObjectives::PRODUCT_CATALOG_SALES, AdCampaignFields::PROMOTED_OBJECT => array('product_catalog_id' => $this->productCatalog->{ProductCatalogFields::ID}))); $this->assertCanCreate($this->adCampaign); $targeting = new TargetingSpecs(); $targeting->{TargetingSpecsFields::GEO_LOCATIONS} = array('countries' => array('US')); $targeting->{TargetingSpecsFields::DYNAMIC_AUDIENCE_IDS} = array($this->productAudience->{ProductAudienceFields::ID}); $this->adSet = new AdSet(null, $this->getConfig()->accountId); $this->adSet->setData(array(AdSetFields::NAME => $this->getConfig()->testRunId, AdSetFields::OPTIMIZATION_GOAL => OptimizationGoals::LINK_CLICKS, AdSetFields::BILLING_EVENT => BillingEvents::IMPRESSIONS, AdSetFields::BID_AMOUNT => 2, AdSetFields::DAILY_BUDGET => 2000, AdSetFields::CAMPAIGN_GROUP_ID => $this->adCampaign->{AdCampaignFields::ID}, AdSetFields::TARGETING => $targeting, AdsetFields::PROMOTED_OBJECT => array('product_set_id' => $this->productSet->{ProductSetFields::ID}))); $this->assertCanCreate($this->adSet); $template = new TemplateData(); $template->setData(array(TemplateDataFields::DESCRIPTION => '{{product.description}}', TemplateDataFields::LINK => 'http://www.example.com/', TemplateDataFields::MESSAGE => 'Test DPA Ad Message', TemplateDataFields::NAME => '{{product.name | titleize}}', TemplateDataFields::MAX_PRODUCT_COUNT => 3, TemplateDataFields::CALL_TO_ACTION => array('type' => CallToActionTypes::SHOP_NOW))); $story = new ObjectStorySpec(); $story->setData(array(ObjectStorySpecFields::PAGE_ID => $this->getConfig()->pageId, ObjectStorySpecFields::TEMPLATE_DATA => $template)); $this->creative = new AdCreative(null, $this->getConfig()->accountId); $this->creative->setData(array(AdCreativeFields::NAME => $this->getConfig()->testRunId, AdCreativeFields::OBJECT_STORY_SPEC => $story, AdCreativeFields::PRODUCT_SET_ID => $this->productSet->{ProductSetFields::ID})); $this->assertCanCreate($this->creative); $this->adGroup = new AdGroup(null, $this->getConfig()->accountId); $this->adGroup->setData(array(AdGroupFields::NAME => 'DPA Test Ad 1 ' . $this->getConfig()->testRunId, AdGroupFields::CAMPAIGN_ID => $this->adSet->{AdSetFields::ID}, AdGroupFields::CREATIVE => array('creative_id' => $this->creative->{AdCreativeFields::ID}))); $this->assertCanCreate($this->adGroup); }
public function tearDown() { $this->adCampaign->delete(); $this->adCampaign = null; parent::tearDown(); }
use FacebookAds\Object\AdAccount; use FacebookAds\Object\Fields\AdAccountFields; $account = (new AdAccount($account_id))->read(array(AdAccountFields::ID, AdAccountFields::NAME, AdAccountFields::ACCOUNT_STATUS)); echo "\nUsing this account: "; echo $account->id . "\n"; // Check the account is active if ($account->{AdAccountFields::ACCOUNT_STATUS} !== 1) { throw new \Exception('This account is not active'); } /** * Step 2 Create the AdCampaign */ use FacebookAds\Object\AdCampaign; use FacebookAds\Object\Fields\AdCampaignFields; use FacebookAds\Object\Values\AdObjectives; $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->validate()->create(); echo "Campaign ID:" . $campaign->id . "\n"; /** * Step 3 Search Targeting */ use FacebookAds\Object\TargetingSearch; use FacebookAds\Object\Search\TargetingSearchTypes; use FacebookAds\Object\TargetingSpecs; use FacebookAds\Object\Fields\TargetingSpecsFields; $results = TargetingSearch::search($type = TargetingSearchTypes::INTEREST, $class = null, $query = 'facebook'); // we'll take the top result for now $target = count($results) ? $results->current() : null; echo "Using target: " . $target->name . "\n"; $targeting = new TargetingSpecs();
/** * @param array $fields * @param array $params * @return Cursor */ public function getAdCampaigns(array $fields = array(), array $params = array()) { return $this->getManyByConnection(AdCampaign::className(), $fields, $params); }
// use FacebookAds\Object\Values\AdObjectives; $campaign = new AdCampaign(null, $ad_account_id); $campaign->setData(array(AdCampaignFields::NAME => 'Video Views Campaign', AdCampaignFields::OBJECTIVE => AdObjectives::VIDEO_VIEWS, AdCampaignFields::STATUS => AdCampaign::STATUS_PAUSED)); $campaign->create(); // _DOC close [ADCAMPAIGN_CREATE_VIDEO_VIEWS] $campaign->delete(); // _DOC open [ADCAMPAIGN_CREATE_LOCAL_AWARENESS] // _DOC vars [ad_account_id:s] // use FacebookAds\Object\AdCampaign; // use FacebookAds\Object\AdCampaignFields; // use FacebookAds\Object\Values\AdObjectives; $campaign = new AdCampaign(null, $ad_account_id); $campaign->setData(array(AdCampaignFields::NAME => 'Local awareness campaign', AdCampaignFields::OBJECTIVE => AdObjectives::LOCAL_AWARENESS, AdCampaignFields::STATUS => AdCampaign::STATUS_PAUSED)); $campaign->create(); // _DOC close [ADCAMPAIGN_CREATE_LOCAL_AWARENESS] $campaign->delete(); $product_catalog = new ProductCatalog(null, $business_id); $product_catalog->setData(array(ProductCatalogFields::NAME => 'Test Catalog')); $product_catalog->create(); $product_catalog_id = $product_catalog->{ProductCatalogFields::ID}; // _DOC open [ADCAMPAIGN_CREATE_OBJECTIVE_PRODUCT_CATELOG_SALES] // _DOC vars [ad_account_id:s, product_catalog_id] // use FacebookAds\Object\AdCampaign; // use FacebookAds\Object\Fields\AdCampaignFields; // use FacebookAds\Object\Values\AdObjectives; $campaign = new AdCampaign(null, $ad_account_id); $campaign->setData(array(AdCampaignFields::NAME => 'Product Catalog Sales Campaign Group', AdCampaignFields::OBJECTIVE => AdObjectives::PRODUCT_CATALOG_SALES, AdCampaignFields::STATUS => AdCampaign::STATUS_PAUSED, AdCampaignFields::PROMOTED_OBJECT => array('product_catalog_id' => $product_catalog_id))); $campaign->create(); // _DOC close [ADCAMPAIGN_CREATE_OBJECTIVE_PRODUCT_CATELOG_SALES] $campaign->delete(); $product_catalog->delete();
/** * @param array $fields * @param array $params * @return Cursor */ public function getAdCampaignsByLabel(array $fields = array(), array $params = array()) { return $this->getManyByConnection(AdCampaign::classname(), $fields, $params, 'adcampaigngroupsbylabels'); }