64 protected $headers = [];
69 protected $params = [];
74 protected $files = [];
97 public function __construct(
FacebookApp $app =
null, $accessToken =
null, $method =
null, $endpoint =
null, array $params = [], $eTag =
null, $graphVersion =
null)
100 $this->setAccessToken($accessToken);
101 $this->setMethod($method);
102 $this->setEndpoint($endpoint);
103 $this->setParams($params);
104 $this->setETag($eTag);
105 $this->graphVersion = $graphVersion ?: Facebook::DEFAULT_GRAPH_VERSION;
117 $this->accessToken = $accessToken;
119 $this->accessToken = $accessToken->getValue();
136 $existingAccessToken = $this->getAccessToken();
137 if (!$existingAccessToken) {
138 $this->setAccessToken($accessToken);
139 } elseif ($accessToken !== $existingAccessToken) {
140 throw new FacebookSDKException(
'Access token mismatch. The access token provided in the FacebookRequest and the one provided in the URL or POST params do not match.');
153 return $this->accessToken;
163 return $this->accessToken ?
new AccessToken($this->accessToken) :
null;
193 if (!$accessTokenEntity = $this->getAccessTokenEntity()) {
197 return $accessTokenEntity->getAppSecretProof($this->app->getSecret());
207 $accessToken = $this->getAccessToken();
220 $this->
method = strtoupper($method);
230 return $this->method;
244 if (!in_array($this->
method, [
'GET',
'POST',
'DELETE'])) {
261 $params = FacebookUrlManipulator::getParamsAsArray($endpoint);
262 if (isset($params[
'access_token'])) {
263 $this->setAccessTokenFromParams($params[
'access_token']);
267 $filterParams = [
'access_token',
'appsecret_proof'];
268 $this->endpoint = FacebookUrlManipulator::removeParamsFromUrl($endpoint, $filterParams);
281 return $this->endpoint;
291 $headers = static::getDefaultHeaders();
294 $headers[
'If-None-Match'] = $this->eTag;
297 return array_merge($this->headers, $headers);
307 $this->headers = array_merge($this->headers, $headers);
331 if (isset($params[
'access_token'])) {
332 $this->setAccessTokenFromParams($params[
'access_token']);
336 unset($params[
'access_token'], $params[
'appsecret_proof']);
340 $params = $this->sanitizeFileParams($params);
341 $this->dangerouslySetParams($params);
355 $this->params = array_merge($this->params, $params);
369 foreach ($params
as $key => $value) {
371 $this->addFile($key, $value);
372 unset($params[$key]);
387 $this->files[$key] = $file;
415 return !
empty($this->files);
425 foreach ($this->files
as $file) {
441 $params = $this->getPostParams();
453 $params = $this->getPostParams();
465 $params = $this->params;
467 $accessToken = $this->getAccessToken();
469 $params[
'access_token'] = $accessToken;
470 $params[
'appsecret_proof'] = $this->getAppSecretProof();
483 if ($this->getMethod() ===
'POST') {
484 return $this->getParams();
497 return $this->graphVersion;
507 $this->validateMethod();
509 $graphVersion = FacebookUrlManipulator::forceSlashPrefix($this->graphVersion);
510 $endpoint = FacebookUrlManipulator::forceSlashPrefix($this->getEndpoint());
512 $url = $graphVersion . $endpoint;
514 if ($this->getMethod() !==
'POST') {
515 $params = $this->getParams();
516 $url = FacebookUrlManipulator::appendParamsToUrl(
$url, $params);
530 'User-Agent' =>
'fb-php-' . Facebook::VERSION,
531 'Accept-Encoding' =>
'*',