56 const VERSION =
'5.6.2';
61 const DEFAULT_GRAPH_VERSION =
'v2.10';
66 const APP_ID_ENV_NAME =
'FACEBOOK_APP_ID';
71 const APP_SECRET_ENV_NAME =
'FACEBOOK_APP_SECRET';
128 'app_id' => getenv(static::APP_ID_ENV_NAME),
129 'app_secret' => getenv(static::APP_SECRET_ENV_NAME),
130 'default_graph_version' => static::DEFAULT_GRAPH_VERSION,
131 'enable_beta_mode' =>
false,
132 'http_client_handler' =>
null,
133 'persistent_data_handler' =>
null,
134 'pseudo_random_string_generator' =>
null,
135 'url_detection_handler' =>
null,
139 throw new FacebookSDKException(
'Required "app_id" key not supplied in config and could not find fallback environment variable "' . static::APP_ID_ENV_NAME .
'"');
142 throw new FacebookSDKException(
'Required "app_secret" key not supplied in config and could not find fallback environment variable "' . static::APP_SECRET_ENV_NAME .
'"');
151 $config[
'pseudo_random_string_generator']
155 $config[
'persistent_data_handler']
158 if (isset(
$config[
'default_access_token'])) {
159 $this->setDefaultAccessToken(
$config[
'default_access_token']);
163 $this->defaultGraphVersion =
$config[
'default_graph_version'];
183 return $this->client;
194 $app = $this->getApp();
195 $client = $this->getClient();
196 $this->oAuth2Client =
new OAuth2Client($app, $client, $this->defaultGraphVersion);
199 return $this->oAuth2Client;
209 return $this->lastResponse;
219 return $this->urlDetectionHandler;
229 $this->urlDetectionHandler = $urlDetectionHandler;
239 return $this->defaultAccessToken;
251 if (is_string($accessToken)) {
252 $this->defaultAccessToken =
new AccessToken($accessToken);
258 $this->defaultAccessToken = $accessToken;
263 throw new \InvalidArgumentException(
'The default access token must be of type "string" or Facebook\AccessToken');
273 return $this->defaultGraphVersion;
284 $this->getOAuth2Client(),
285 $this->persistentDataHandler,
286 $this->urlDetectionHandler,
287 $this->pseudoRandomStringGenerator
333 public function get($endpoint, $accessToken =
null, $eTag =
null, $graphVersion =
null)
335 return $this->sendRequest(
358 public function post($endpoint, array $params = [], $accessToken =
null, $eTag =
null, $graphVersion =
null)
360 return $this->sendRequest(
383 public function delete($endpoint, array $params = [], $accessToken =
null, $eTag =
null, $graphVersion =
null)
385 return $this->sendRequest(
406 return $this->getPaginationResults($graphEdge,
'next');
420 return $this->getPaginationResults($graphEdge,
'previous');
436 if (!$paginationRequest) {
440 $this->lastResponse = $this->client->sendRequest($paginationRequest);
444 $graphEdge = $this->lastResponse->getGraphEdge($subClassName,
false);
446 return count($graphEdge) > 0 ? $graphEdge :
null;
463 public function sendRequest($method, $endpoint, array $params = [], $accessToken =
null, $eTag =
null, $graphVersion =
null)
465 $accessToken = $accessToken ?: $this->defaultAccessToken;
466 $graphVersion = $graphVersion ?: $this->defaultGraphVersion;
467 $request = $this->request($method, $endpoint, $params, $accessToken, $eTag, $graphVersion);
469 return $this->lastResponse = $this->client->sendRequest($request);
483 public function sendBatchRequest(array $requests, $accessToken =
null, $graphVersion =
null)
485 $accessToken = $accessToken ?: $this->defaultAccessToken;
486 $graphVersion = $graphVersion ?: $this->defaultGraphVersion;
494 return $this->lastResponse = $this->client->sendBatchRequest($batchRequest);
507 $accessToken = $accessToken ?: $this->defaultAccessToken;
508 $graphVersion = $graphVersion ?: $this->defaultGraphVersion;
532 public function request($method, $endpoint, array $params = [], $accessToken =
null, $eTag =
null, $graphVersion =
null)
534 $accessToken = $accessToken ?: $this->defaultAccessToken;
535 $graphVersion = $graphVersion ?: $this->defaultGraphVersion;
590 public function uploadVideo($target, $pathToFile, $metadata = [], $accessToken =
null, $maxTransferTries = 5, $graphVersion =
null)
592 $accessToken = $accessToken ?: $this->defaultAccessToken;
593 $graphVersion = $graphVersion ?: $this->defaultGraphVersion;
596 $endpoint =
'/'.$target.
'/videos';
597 $file = $this->videoToUpload($pathToFile);
598 $chunk = $uploader->start($endpoint, $file);
601 $chunk = $this->maxTriesTransfer($uploader, $endpoint, $chunk, $maxTransferTries);
602 }
while (!$chunk->isLastChunk());
605 'video_id' => $chunk->getVideoId(),
606 'success' => $uploader->finish($endpoint, $chunk->getUploadSessionId(), $metadata),
624 $newChunk = $uploader->
transfer($endpoint, $chunk, $retryCountdown < 1);
626 if ($newChunk !== $chunk) {
633 return $this->maxTriesTransfer($uploader, $endpoint, $chunk, $retryCountdown);