public function testCrudAccess() { $cursor = TargetingSearch::search(TargetingSearchTypes::CITY, null, 'Lon'); /* @var $category AbstractCrudObject */ $result = $cursor->current(); $this->assertTrue($result instanceof TargetingSearch); $this->assertNotEmpty($result->key); }
*/ 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(); $targeting->{TargetingSpecsFields::GEO_LOCATIONS} = array('countries' => array('GB')); $targeting->{TargetingSpecsFields::INTERESTS} = array(array('id' => $target->id, 'name' => $target->name)); /** * Step 4 Create the AdSet */ use FacebookAds\Object\AdSet; use FacebookAds\Object\Fields\AdSetFields; use FacebookAds\Object\Values\OptimizationGoals; use FacebookAds\Object\Values\BillingEvents; $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)));
// _DOC close [SEARCH_TARGETING_CATEGORY_WITH_INTERESTS] // _DOC open [SEARCH_TARGETING_CATEGORY_WITH_BEHAVIORS] // use FacebookAds\Object\TargetingSearch; // use FacebookAds\Object\Search\TargetingSearchTypes; $result = TargetingSearch::search(TargetingSearchTypes::TARGETING_CATEGORY, 'behaviors'); // _DOC close [SEARCH_TARGETING_CATEGORY_WITH_BEHAVIORS] // _DOC open [SEARCH_LOCALE] // use FacebookAds\Object\TargetingSearch; // use FacebookAds\Object\Search\TargetingSearchTypes; $result = TargetingSearch::search(TargetingSearchTypes::LOCALE, null, 'en'); // _DOC close [SEARCH_LOCALE] // _DOC open [SEARCH_EDUCATION_SCHOOL] // use FacebookAds\Object\TargetingSearch; // use FacebookAds\Object\Search\TargetingSearchTypes; $result = TargetingSearch::search(TargetingSearchTypes::EDUCATION, null, 'ha'); // _DOC close [SEARCH_EDUCATION_SCHOOL] // _DOC open [SEARCH_EDUCATION_MAJOR] // use FacebookAds\Object\TargetingSearch; // use FacebookAds\Object\Search\TargetingSearchTypes; $result = TargetingSearch::search(TargetingSearchTypes::MAJOR, null, 'ph'); // _DOC close [SEARCH_EDUCATION_MAJOR] // _DOC open [SEARCH_WORK_EMPLOYER] // use FacebookAds\Object\TargetingSearch; // use FacebookAds\Object\Search\TargetingSearchTypes; $result = TargetingSearch::search(TargetingSearchTypes::EMPLOYER, null, 'mic'); // _DOC close [SEARCH_WORK_EMPLOYER] // _DOC open [SEARCH_WORK_POSITION] // use FacebookAds\Object\TargetingSearch; // use FacebookAds\Object\Search\TargetingSearchTypes; $result = TargetingSearch::search(TargetingSearchTypes::POSITION, null, 'ana'); // _DOC close [SEARCH_WORK_POSITION]