/** * @depends testCustomAudiences */ public function testAppIdsPayload() { $ca = new CustomAudience(null, $this->getActId()); $ca->{CustomAudienceFields::NAME} = $this->getTestRunId(); $ca->create(); $users = array($this->getApi()->call('/me')->getContent()['id']); $add = $ca->addUsers($users, CustomAudienceTypes::ID, array($this->getAppId())); $this->assertClusterChangesResponse($ca, $users, $add); $remove = $ca->removeUsers($users, CustomAudienceTypes::ID, array($this->getAppId())); $this->assertClusterChangesResponse($ca, $users, $remove); $optout = $ca->optOutUsers($users, CustomAudienceTypes::ID, array($this->getAppId())); $this->assertSuccessResponse($optout); $ca->delete(); }
public function getAudiences(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, '/audiences', new CustomAudience(), 'EDGE', CustomAudience::getFieldsEnum()->getValues(), new TypeChecker($param_types, $enums)); $request->addParams($params); $request->addFields($fields); return $pending ? $request : $request->execute(); }
// should begin with "act_" (eg: $account_id = 'act_1234567890';) $account_id = null; // Configurations - End if (is_null($access_token) || is_null($app_id) || is_null($app_secret)) { throw new \Exception('You must set your access token, app id and app secret before executing'); } if (is_null($account_id)) { throw new \Exception('You must set your account id before executing'); } define('SDK_DIR', __DIR__ . '/..'); // Path to the SDK directory $loader = (include SDK_DIR . '/vendor/autoload.php'); use FacebookAds\Api; Api::init($app_id, $app_secret, $access_token); // use the namespace for Custom Audiences and Fields use FacebookAds\Object\CustomAudience; use FacebookAds\Object\Fields\CustomAudienceFields; use FacebookAds\Object\Values\CustomAudienceTypes; // Create a custom audience object, setting the parent to be the account id $audience = new CustomAudience(null, $account_id); $audience->setData(array(CustomAudienceFields::NAME => 'My Custom Audiece', CustomAudienceFields::DESCRIPTION => 'Lots of people')); // Create the audience $audience->create(); echo "Audience ID: " . $audience->id . "\n"; // Assuming you have an array of emails: // NOTE: The SDK will hash (SHA-2) your data before submitting // it to Facebook servers $emails = array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'); $audience->addUsers($emails, CustomAudienceTypes::EMAIL); $audience->read(array(CustomAudienceFields::APPROXIMATE_COUNT)); echo "Estimated Size:" . $audience->{CustomAudienceFields::APPROXIMATE_COUNT} . "\n";
public function updateSelf(array $fields = array(), array $params = array(), $pending = false) { $this->assureId(); $param_types = array('claim_objective' => 'claim_objective_enum', 'content_type' => 'content_type_enum', 'description' => 'string', 'event_source_group' => 'string', 'lookalike_spec' => 'string', 'name' => 'string', 'opt_out_link' => 'string', 'product_set_id' => 'string', 'retention_days' => 'unsigned int', 'rule' => 'string'); $enums = array('claim_objective_enum' => CustomAudienceClaimObjectiveValues::getInstance()->getValues(), 'content_type_enum' => CustomAudienceContentTypeValues::getInstance()->getValues()); $request = new ApiRequest($this->api, $this->data['id'], RequestInterface::METHOD_POST, '/', new CustomAudience(), 'NODE', CustomAudience::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 getCustomAudiences(array $fields = array(), array $params = array()) { return $this->getManyByConnection(CustomAudience::className(), $fields, $params); }
$response = $api->call('/me/accounts'); $data = $response->getContent(); $page_token = ''; foreach ($data['data'] as $page) { if ($page['id'] == $page_id) { $page_token = $page['access_token']; break; } } if ($page_token === '') { throw new \InvalidArgumentException('Page access token for the page id ' . $page_id . ' cannot be found.'); } $page_session = new Session($config->appId, $config->appSecret, $page_token); $page_api = new Api($api->getHttpClient(), $page_session); $page_api->setLogger($api->getLogger()); $request = $page_api->prepareRequest('/' . $page_id . '/videos', RequestInterface::METHOD_POST); $request->setLastLevelDomain('graph-video'); $request->getFileParams()->offsetSet('source', $video_path); $response = $page_api->executeRequest($request); $data = $response->getContent(); $video_id = is_string($data) ? $data : (string) $data['id']; // _DOC open [CUSTOM_AUDIENCE_CREATE_VIDEO_VIEWS_RETARGET] // _DOC vars [ad_account_id:s, video_id] // use FacebookAds\Object\CustomAudience; // use FacebookAds\Object\Fields\CustomAudienceFields; // use FacebookAds\Object\Values\CustomAudienceSubtypes; $lookalike = new CustomAudience(null, $ad_account_id); $lookalike->setData(array(CustomAudienceFields::SUBTYPE => CustomAudienceSubtypes::LOOKALIKE, CustomAudienceFields::LOOKALIKE_SPEC => array('ratio' => 0.01, 'country' => 'US', 'engagement_specs' => array(array('action.type' => 'video_view', 'post' => $video_id)), 'conversion_type' => 'dynamic_rule'))); $lookalike->create(); // _DOC close [CUSTOM_AUDIENCE_CREATE_VIDEO_VIEWS_RETARGET] $lookalike->delete();
public function createProductAudience(array $fields = array(), array $params = array(), $pending = false) { $this->assureId(); $param_types = array('associated_audience_id' => 'unsigned int', 'creation_params' => 'map', 'description' => 'string', 'exclusions' => 'list<Object>', 'inclusions' => 'list<Object>', 'name' => 'string', 'opt_out_link' => 'string', 'parent_audience_id' => 'unsigned int', 'product_set_id' => 'string', 'subtype' => 'subtype_enum', 'tags' => 'list<string>'); $enums = array('subtype_enum' => array('CUSTOM', 'WEBSITE', 'APP', 'OFFLINE_CONVERSION', 'CLAIM', 'PARTNER', 'MANAGED', 'VIDEO', 'LOOKALIKE', 'ENGAGEMENT', 'DATA_SET', 'BAG_OF_ACCOUNTS', 'STUDY_RULE_AUDIENCE')); $request = new ApiRequest($this->api, $this->data['id'], RequestInterface::METHOD_POST, '/product_audiences', new CustomAudience(), 'EDGE', CustomAudience::getFieldsEnum()->getValues(), new TypeChecker($param_types, $enums)); $request->addParams($params); $request->addFields($fields); return $pending ? $request : $request->execute(); }