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 getAdCreatives(array $fields = array(), array $params = array(), $pending = false) { $this->assureId(); $param_types = array(); $enums = array(); $request = new ApiRequest($this->api, $this->data['id'], RequestInterface::METHOD_GET, '/adcreatives', new AdCreative(), 'EDGE', AdCreative::getFieldsEnum()->getValues(), new TypeChecker($param_types, $enums)); $request->addParams($params); $request->addFields($fields); return $pending ? $request : $request->execute(); }
public function testAdPreviews() { // Preview with actual creative $previews = $this->adCreative->getAdPreviews(array(), array(AdPreviewFields::AD_FORMAT => AdFormats::RIGHT_COLUMN_STANDARD)); $this->assertNotEquals(0, $previews->count()); $preview = $previews->offsetGet(0); $this->assertRegExp('/iframe/', $preview->{AdPreviewFields::BODY}); // Preview with actual adgroup $previews = $this->adGroup->getAdPreviews(array(), array(AdPreviewFields::AD_FORMAT => AdFormats::RIGHT_COLUMN_STANDARD)); $this->assertNotEquals(0, $previews->count()); $preview = $previews->offsetGet(0); $this->assertRegExp('/iframe/', $preview->{AdPreviewFields::BODY}); // Preview with creative specs $account = new AdAccount($this->getActId()); $previews = $account->getAdPreviews(array(), array(AdPreviewFields::CREATIVE => array(AdCreativeFields::BODY => 'Testing the creative preview', AdCreativeFields::OBJECT_ID => $this->getPageId()), AdPreviewFields::AD_FORMAT => AdFormats::RIGHT_COLUMN_STANDARD)); $this->assertNotEquals(0, $previews->count()); $preview = $previews->offsetGet(0); $this->assertRegExp('/iframe/', $preview->{AdPreviewFields::BODY}); }
public function tearDown() { if ($this->adSet) { $this->adSet->delete(); $this->adSet = null; } if ($this->campaign) { $this->campaign->delete(); $this->campaign = null; } if ($this->adCreative) { $this->adCreative->delete(); $this->adCreative = null; } if ($this->adImage) { $this->adImage->delete(); $this->adImage = null; } parent::tearDown(); }
/** * @param array $fields * @param array $params * @return Cursor */ public function getAdCreatives(array $fields = array(), array $params = array()) { return $this->getManyByConnection(AdCreative::className(), $fields, $params); }
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); }
$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";
public function getAdCreativesByLabels(array $fields = array(), array $params = array(), $pending = false) { $this->assureId(); $param_types = array('ad_label_ids' => 'list<string>', 'operator' => 'operator_enum'); $enums = array('operator_enum' => AdCreativeOperatorValues::getInstance()->getValues()); $request = new ApiRequest($this->api, $this->data['id'], RequestInterface::METHOD_GET, '/adcreativesbylabels', new AdCreative(), 'EDGE', AdCreative::getFieldsEnum()->getValues(), new TypeChecker($param_types, $enums)); $request->addParams($params); $request->addFields($fields); return $pending ? $request : $request->execute(); }
/** * @param array $fields * @param array $params * @return Cursor */ public function getAdCreativesByLabel(array $fields = array(), array $params = array()) { return $this->getManyByConnection(AdCreative::classname(), $fields, $params, 'adcreativesbylabels'); }
public function updateSelf(array $fields = array(), array $params = array(), $pending = false) { $this->assureId(); $param_types = array('account_id' => 'string', 'adlabels' => 'list<Object>', 'name' => 'string', 'run_status' => 'unsigned int'); $enums = array(); $request = new ApiRequest($this->api, $this->data['id'], RequestInterface::METHOD_POST, '/', new AdCreative(), 'NODE', AdCreative::getFieldsEnum()->getValues(), new TypeChecker($param_types, $enums)); $request->addParams($params); $request->addFields($fields); return $pending ? $request : $request->execute(); }
$image = new AdImage(null, $ad_account_id); $image->{AdImageFields::FILENAME} = $image_path; $image->create(); $image_hash = $image->{AdImageFields::HASH}; // _DOC open [ADGROUP_CREATE_INLINE_CREATIVE] // _DOC vars [ad_account_id:s, image_hash:s, ad_set_id:s] // use FacebookAds\Object\AdCreative; // use FacebookAds\Object\AdGroup; // use FacebookAds\Object\TargetingSpecs; // use FacebookAds\Object\Fields\AdCreativeFields; // use FacebookAds\Object\Fields\AdImageFields; // use FacebookAds\Object\Fields\AdGroupFields; // First, upload the ad image that you will use in your ad creative // Please refer to Ad Image Create for details. // Then, use the image hash returned from above $creative = new AdCreative(null, $ad_account_id); $creative->setData(array(AdCreativeFields::TITLE => 'My Test Creative', AdCreativeFields::BODY => 'My Test Ad Creative Body', AdCreativeFields::OBJECT_URL => 'https://www.facebook.com/facebook', AdCreativeFields::IMAGE_HASH => $image_hash)); // Finally, create your ad along with ad creative. // Please note that the ad creative is not created independently, rather its // data structure is appended to the ad group $adgroup = new AdGroup(null, $ad_account_id); $adgroup->setData(array(AdGroupFields::NAME => 'My Ad', AdGroupFields::CAMPAIGN_ID => $ad_set_id, AdGroupFields::CREATIVE => $creative, AdGroupFields::ADGROUP_STATUS => AdGroup::STATUS_PAUSED)); $adgroup->create(); // _DOC close [ADGROUP_CREATE_INLINE_CREATIVE] // fetch the id of the generated creative $adgroup->read(array(AdGroupFields::CREATIVE)); $creative->{AdCreativeFields::ID} = $adgroup->{AdGroupFields::CREATIVE}['id']; // _DOC open [ADGROUP_GET_TARGETING_DESCRIPTION] // _DOC vars [ad_group_id] // use FacebookAds\Object\AdGroup; $adgroup = new AdGroup($ad_group_id);
// _DOC vars [ad_account_id:s, page_id, link:s, product_set_id_1] // use FacebookAds\Object\AdCreative; // use FacebookAds\Object\ObjectStorySpec; // use FacebookAds\Object\ObjectStory\TemplateData; // use FacebookAds\Object\Fields\AdCreativeFields; // use FacebookAds\Object\Fields\ObjectStorySpecFields; $object_story_spec = new ObjectStorySpec(); $object_story_spec->setData(array(ObjectStorySpecFields::PAGE_ID => $page_id, ObjectStorySpecFields::TEMPLATE_DATA => (new TemplateData())->setData(array('message' => 'Test {{product.name | titleize}}', 'link' => $link, 'name' => 'Headline {{product.price}}', 'description' => 'Description {{product.description}}', 'max_product_count' => 3)))); $creative = new AdCreative(null, $ad_account_id); $creative->setData(array(AdCreativeFields::NAME => 'Dynamic Ad Template Creative Sample', AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec, AdCreativeFields::PRODUCT_SET_ID => $product_set_id_1)); $creative->create(); // _DOC close [ADCREATIVE_CREATE_DPA_RETARGETING] $creative_id = $creative->{AdCreativeFields::ID}; $creative->delete(); $feed->delete(); $product_set->delete(); $product_catalog->delete(); // FIXME excluded from runtime return; $retailer_id = 'rid'; // _DOC open [ADCREATIVE_READ_DPA_PREVIEW] // _DOC vars [creative_id, catalog_id, retailer_id:s] // use FacebookAds\Object\AdCreative; // use FacebookAds\Object\AdPreview; // use FacebookAds\Object\Fields\AdCreativeFields; // use FacebookAds\Object\Fields\AdPreviewFields; // use FacebookAds\Object\Values\AdFormats; // $creative = new AdCreative($creative_id); $creative = new AdCreative($creative_id); $preview = $creative->getAdPreviews(array(), array(AdPreviewFields::AD_FORMAT => AdFormats::DESKTOP_FEED_STANDARD, AdPreviewFields::PRODUCT_ITEM_IDS => array('catalog:' . $catalog_id . ':' . base64_encode($retailer_id)))); // _DOC close [ADCREATIVE_READ_DPA_PREVIEW]