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->adCampaign = new AdCampaign(null, $this->getConfig()->accountId);
     $this->adCampaign->{AdCampaignFields::NAME} = $this->getConfig()->testRunId;
     $this->adCampaign->create();
     $this->adSet = new AdSet(null, $this->getConfig()->accountId);
     $this->adSet->{AdSetFields::CAMPAIGN_GROUP_ID} = (int) $this->adCampaign->{AdSetFields::ID};
     $this->adSet->{AdSetFields::NAME} = $this->getConfig()->testRunId;
     $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->{AdGroupFields::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();
     $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->adGroup = new AdGroup(null, $this->getConfig()->accountId);
     $this->adGroup->{AdGroupFields::ADGROUP_STATUS} = AdGroup::STATUS_PAUSED;
     $this->adGroup->{AdGroupFields::NAME} = $this->getConfig()->testRunId;
     $this->adGroup->{AdGroupFields::CAMPAIGN_ID} = (int) $this->adSet->{AdSetFields::ID};
     $this->adGroup->{AdGroupFields::CREATIVE} = array('creative_id' => $this->adCreative->{AdCreativeFields::ID});
     $this->adGroup->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";