public function testCrud() { $account = new AdAccount($this->getConfig()->accountId); $this->assertCanRead($account); $name = $account->read(array(AdAccountFields::NAME))->{AdAccountFields::NAME}; $this->assertCanUpdate($account, array(AdAccountFields::NAME => $this->getConfig()->testRunId)); // Restore original account name $account->{AdAccountFields::NAME} = $name; $account->save(); $this->assertCannotDelete($account); $targeting = new TargetingSpecs(); $targeting->setData(array(TargetingSpecsFields::GEO_LOCATIONS => array('countries' => array('US', 'JP')), TargetingSpecsFields::GENDERS => array(1), TargetingSpecsFields::AGE_MIN => 20, TargetingSpecsFields::AGE_MAX => 24)); $creative = (new AdCreative())->setData(array(AdCreativeFields::TITLE => 'My Test Creative', AdCreativeFields::BODY => 'My Test Ad Creative Body', AdCreativeFields::OBJECT_URL => 'https://www.facebook.com/facebook')); $targeting_params = array('targeting_spec' => $targeting->exportData()); $label_params = array('ad_label_ids' => array($this->adLabel->{AdLabelFields::ID})); $this->assertCanFetchConnection($account, 'getActivities'); $this->assertCanFetchConnection($account, 'getAdUsers'); $this->assertCanFetchConnection($account, 'getCampaigns'); $this->assertCanFetchConnection($account, 'getAdSets'); $this->assertCanFetchConnection($account, 'getAds'); $this->assertCanFetchConnection($account, 'getAdCreatives'); $this->assertCanFetchConnection($account, 'getAdImages'); $this->assertCanFetchConnection($account, 'getAdsPixels'); $this->assertCanFetchConnection($account, 'getAdVideos'); $this->assertCanFetchConnection($account, 'getBroadCategoryTargeting'); $this->assertCanFetchConnection($account, 'getConnectionObjects'); $this->assertCanFetchConnection($account, 'getCustomAudiences'); $this->assertCanFetchConnection($account, 'getConversionPixels'); $this->assertCanFetchConnection($account, 'getPartnerCategories'); $this->assertCanFetchConnection($account, 'getRateCards'); $this->assertCanFetchConnection($account, 'getReachEstimate', array(), array_merge($targeting_params, array('optimize_for' => OptimizationGoals::OFFSITE_CONVERSIONS))); if (!$this->shouldSkipTest('no_reach_and_frequency')) { $this->assertCanFetchConnection($account, 'getReachFrequencyPredictions'); } $this->assertCanFetchConnection($account, 'getTargetingDescription', array(), $targeting_params); $this->assertCanFetchConnection($account, 'getTransactions'); $this->assertCanFetchConnection($account, 'getAdPreviews', array(), array('ad_format' => AdFormats::DESKTOP_FEED_STANDARD, 'creative' => $creative->exportData())); $this->assertCanFetchConnection($account, 'getInsights'); $this->assertCanFetchConnection($account, 'getInsightsAsync'); $this->assertCanFetchConnection($account, 'getAgencies'); $this->assertCanFetchConnection($account, 'getMinimumBudgets'); $this->assertCanFetchConnection($account, 'getAdLabels'); $this->assertCanFetchConnection($account, 'getCampaignsByLabel', array(), $label_params); $this->assertCanFetchConnection($account, 'getAdSetsByLabel', array(), $label_params); $this->assertCanFetchConnection($account, 'getAdsByLabel', array(), $label_params); $this->assertCanFetchConnection($account, 'getAdCreativesByLabel', array(), $label_params); if (!$this->getSkippableFeaturesManager()->isSkipKey('no_business_manager')) { $account->grantAgencyAcccess($this->getConfig()->secondaryBusinessId, array(AdAccountRoles::GENERAL_USER)); $account->revokeAgencyAccess($this->getConfig()->secondaryBusinessId); } }
public function testCrud() { $account = new AdAccount($this->getConfig()->accountId); $this->assertCanRead($account); $name = $account->read(array(AdAccountFields::NAME))->{AdAccountFields::NAME}; $this->assertCanUpdate($account, array(AdAccountFields::NAME => $this->getConfig()->testRunId)); // Restore original account name $account->{AdAccountFields::NAME} = $name; $account->save(); $this->assertCannotDelete($account); $this->assertCanFetchConnection($account, 'getActivities'); $this->assertCanFetchConnection($account, 'getAdUsers'); $this->assertCanFetchConnection($account, 'getAdCampaigns'); $this->assertCanFetchConnection($account, 'getAdSets'); $this->assertCanFetchConnection($account, 'getAdGroups'); $this->assertCanFetchConnection($account, 'getAdCreatives'); $this->assertCanFetchConnection($account, 'getAdImages'); $this->assertCanFetchConnection($account, 'getAdsPixels'); $this->assertCanFetchConnection($account, 'getAdVideos'); $this->assertCanFetchConnection($account, 'getBroadCategoryTargeting'); $this->assertCanFetchConnection($account, 'getConnectionObjects'); $this->assertCanFetchConnection($account, 'getCustomAudiences'); $this->assertCanFetchConnection($account, 'getConversionPixels'); $this->assertCanFetchConnection($account, 'getRateCards'); $this->assertCanFetchConnection($account, 'getAdCreativesByLabel'); if (!$this->shouldSkipTest('no_reach_and_frequency')) { $this->assertCanFetchConnection($account, 'getReachEstimate', array(), array('targeting_spec' => array('geo_locations' => array('countries' => array('US'))))); } $targeting = new TargetingSpecs(); $targeting->setData(array(TargetingSpecsFields::GEO_LOCATIONS => array('countries' => array('US', 'JP')), TargetingSpecsFields::GENDERS => array(1), TargetingSpecsFields::AGE_MIN => 20, TargetingSpecsFields::AGE_MAX => 24)); $params = array('targeting_spec' => $targeting->exportData()); $this->assertCanFetchConnection($account, 'getTargetingDescription', array(), $params); $this->assertCanFetchConnection($account, 'getTransactions'); $this->assertCanFetchConnection($account, 'getAgencies'); $this->assertCanFetchConnection($account, 'getInsights'); $this->assertCanFetchConnection($account, 'getInsightsAsync'); if (!$this->getSkippableFeaturesManager()->isSkipKey('no_business_manager')) { $account->grantAgencyAcccess($this->getConfig()->secondaryBusinessId, array(AdAccountRoles::GENERAL_USER)); $account->revokeAgencyAccess($this->getConfig()->secondaryBusinessId); } }
// use FacebookAds\Object\Fields\InsightsFields; // use FacebookAds\Object\Values\InsightsPresets; $account = new AdAccount($ad_account_id); $params = array('date_preset' => InsightsPresets::LAST_30_DAYS, 'filtering' => array(array('field' => 'adgroup.adlabels', 'operator' => 'ANY', 'value' => array($label_name)))); $fields = array(InsightsFields::CLICKS, InsightsFields::CPC, InsightsFields::TOTAL_ACTIONS); $stats = $account->getInsights($fields, $params); // _DOC close [ADACCOUNT_GET_INSIGHTS_ADLABEL] $label->delete(); unset($label); // _DOC open [ADACCOUNT_GET_TARGETING_DESCRIPTION] // _DOC vars [ad_account_id:s] // use FacebookAds\Object\AdAccount; // use FacebookAds\Object\Fields\TargetingSpecsFields; // use FacebookAds\Object\TargetingSpecs; $account = new AdAccount($ad_account_id); $targeting = new TargetingSpecs(); $targeting->setData(array(TargetingSpecsFields::GEO_LOCATIONS => array('countries' => array('US', 'JP')), TargetingSpecsFields::GENDERS => array(1), TargetingSpecsFields::AGE_MIN => 20, TargetingSpecsFields::AGE_MAX => 24)); $params = array('targeting_spec' => $targeting->exportData()); $targeting_description = $account->getTargetingDescription(array(), $params); // Output targeting description foreach ($targeting_description->targetingsentencelines as $description) { echo $description['content'] . PHP_EOL; foreach ($description['children'] as $child) { echo "\t" . $child . PHP_EOL; } } // _DOC close [ADACCOUNT_GET_TARGETING_DESCRIPTION] unset($account); $creative_spec = array(AdCreativeFields::OBJECT_STORY_ID => $post_id); $format = AdFormats::DESKTOP_FEED_STANDARD; // _DOC open [ADACCOUNT_GET_PREVIEWS]