コード例 #1
0
ファイル: Api.php プロジェクト: bmaorlo/video-ads
 private function createAd($adSetId, $creativeId)
 {
     $data = array(AdFields::NAME => 'My Ad ' . date("Y-m-d H:i:s"), AdFields::ADSET_ID => $adSetId, AdFields::CREATIVE => array('creative_id' => $creativeId));
     $ad = new Ad(null, 'act_' . $this->adAccountId);
     $ad->setData($data);
     $ad->create(array(Ad::STATUS_PARAM_NAME => Ad::STATUS_PAUSED));
     return $ad->getData()[Ad::FIELD_ID];
 }
コード例 #2
0
 public function testDynamicProductAdsCreation()
 {
     $this->campaign = new Campaign(null, $this->getConfig()->accountId);
     $this->campaign->setData(array(CampaignFields::NAME => $this->getConfig()->testRunId, CampaignFields::OBJECTIVE => AdObjectives::PRODUCT_CATALOG_SALES, CampaignFields::PROMOTED_OBJECT => array('product_catalog_id' => $this->productCatalog->{ProductCatalogFields::ID})));
     $this->assertCanCreate($this->campaign);
     $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_ID => $this->campaign->{CampaignFields::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::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->ad = new Ad(null, $this->getConfig()->accountId);
     $this->ad->setData(array(AdFields::NAME => 'DPA Test Ad 1 ' . $this->getConfig()->testRunId, AdFields::ADSET_ID => $this->adSet->{AdSetFields::ID}, AdFields::CREATIVE => array('creative_id' => $this->creative->{AdCreativeFields::ID})));
     $this->assertCanCreate($this->ad);
 }
コード例 #3
0
$adset = new AdSet(null, $account->id);
$adset->setData(array(AdSetFields::NAME => 'My First AdSet', AdSetFields::CAMPAIGN_ID => $campaign->id, AdSetFields::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 Ad
 */
use FacebookAds\Object\Ad;
use FacebookAds\Object\Fields\AdFields;
$ad = new Ad(null, $account->id);
$ad->setData(array(AdFields::CREATIVE => array('creative_id' => $creative->id), AdFields::NAME => 'My First Ad', AdFields::ADSET_ID => $adset->id));
$ad->create();
echo 'Ad ID:' . $ad->id . "\n";