$api = Api::instance(); $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]
protected function setupApi() { $this->api = new Api($this->getHttpClient(), $this->getSession()); $this->api->setLogger($this->getLogger()); Api::setInstance($this->api); }
public function testCall() { $request = $this->createRequestMock(); $request->method('execute')->willReturn($this->createResponseMock()); $request->method('getQueryParams')->willReturn($this->createParametersMock()); $request->method('getBodyParams')->willReturn($this->createParametersMock()); $request->expects($this->exactly(2))->method('setMethod')->with($this->logicalOr(RequestInterface::METHOD_GET, RequestInterface::METHOD_POST)); $request->expects($this->exactly(2))->method('setGraphVersion')->with($this->equalTo($this->createApi()->getDefaultGraphVersion())); $request->expects($this->exactly(2))->method('setPath')->with($this->equalTo('/<PATH>')); $client = $this->createClientMock(); $client->method('createRequest')->willReturn($request); $session = $this->createSessionMock(); $session->method('getAppSecretProof')->willReturn('<APP_SECRET_PROOF>'); $logger = $this->createLoggerMock(); $logger->expects($this->exactly(2))->method('logRequest'); $logger->expects($this->exactly(2))->method('logResponse'); $api = new Api($client, $session); $api->setLogger($logger); // HTTP GET request $request->expects($this->exactly(1))->method('getQueryParams'); $response = $api->call('/<PATH>'); $this->assertTrue($response instanceof ResponseInterface); // HTTP POST request $request->expects($this->exactly(1))->method('getBodyParams'); $api->call('/<PATH>', RequestInterface::METHOD_POST, array('param' => 'value')); $this->assertTrue($response instanceof ResponseInterface); }