41 const BASE_GRAPH_URL =
'https://graph.facebook.com';
46 const BASE_GRAPH_VIDEO_URL =
'https://graph-video.facebook.com';
51 const BASE_GRAPH_URL_BETA =
'https://graph.beta.facebook.com';
56 const BASE_GRAPH_VIDEO_URL_BETA =
'https://graph-video.beta.facebook.com';
61 const DEFAULT_REQUEST_TIMEOUT = 60;
66 const DEFAULT_FILE_UPLOAD_REQUEST_TIMEOUT = 3600;
71 const DEFAULT_VIDEO_UPLOAD_REQUEST_TIMEOUT = 7200;
76 protected $enableBetaMode =
false;
86 public static $requestCount = 0;
96 $this->httpClientHandler = $httpClientHandler ?: $this->detectHttpClientHandler();
97 $this->enableBetaMode = $enableBeta;
107 $this->httpClientHandler = $httpClientHandler;
117 return $this->httpClientHandler;
137 $this->enableBetaMode = $betaMode;
149 if ($postToVideoUrl) {
150 return $this->enableBetaMode ? static::BASE_GRAPH_VIDEO_URL_BETA : static::BASE_GRAPH_VIDEO_URL;
153 return $this->enableBetaMode ? static::BASE_GRAPH_URL_BETA : static::BASE_GRAPH_URL;
166 $url = $this->getBaseGraphUrl($postToVideoUrl) . $request->
getUrl();
172 'Content-Type' =>
'multipart/form-data; boundary=' . $requestBody->getBoundary(),
177 'Content-Type' =>
'application/x-www-form-urlencoded',
185 $requestBody->getBody(),
200 if (get_class($request) ===
'Facebook\FacebookRequest') {
204 list(
$url, $method, $headers, $body) = $this->prepareRequestMessage($request);
207 $timeOut = static::DEFAULT_REQUEST_TIMEOUT;
209 $timeOut = static::DEFAULT_FILE_UPLOAD_REQUEST_TIMEOUT;
211 $timeOut = static::DEFAULT_VIDEO_UPLOAD_REQUEST_TIMEOUT;
216 $rawResponse = $this->httpClientHandler->send(
$url, $method, $body, $headers, $timeOut);
218 static::$requestCount++;
222 $rawResponse->getBody(),
223 $rawResponse->getHttpResponseCode(),
227 if ($returnResponse->isError()) {
228 throw $returnResponse->getThrownException();
231 return $returnResponse;
246 $facebookResponse = $this->sendRequest($request);