$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();