/** * Creates a JavaScript Login Helper for the given application id, or the * default if not provided. * * @param string $appId * * @throws FacebookSDKException */ public function __construct($appId = null) { $this->appId = FacebookSession::_getTargetAppId($appId); if (!$this->appId) { throw new FacebookSDKException('You must provide or set a default application id.'); } }
/** * Handles a response from Facebook, including a CSRF check, and returns a * FacebookSession. * * @return FacebookSession|null */ public function getSessionFromRedirect() { $this->loadState(); if ($this->isValidRedirect()) { $params = array('client_id' => FacebookSession::_getTargetAppId($this->appId), 'redirect_uri' => $this->redirectUrl, 'client_secret' => FacebookSession::_getTargetAppSecret($this->appSecret), 'code' => $this->getCode()); $response = (new FacebookRequest(FacebookSession::newAppSession($this->appId, $this->appSecret), 'GET', '/oauth/access_token', $params))->execute()->getResponse(); if (isset($response['access_token'])) { return new FacebookSession($response['access_token']); } } return null; }
/** * Handles a response from Facebook, including a CSRF check, and returns a * FacebookSession. * * @return FacebookSession|null */ public function getSessionFromRedirect() { if ($this->isValidRedirect()) { $params = array('client_id' => FacebookSession::_getTargetAppId($this->appId), 'redirect_uri' => $this->redirectUrl, 'client_secret' => FacebookSession::_getTargetAppSecret($this->appSecret), 'code' => $this->getCode()); $response = (new FacebookRequest(FacebookSession::newAppSession($this->appId, $this->appSecret), 'GET', '/oauth/access_token', $params))->execute()->getResponse(); // Graph v2.3 and greater return objects on the /oauth/access_token endpoint $accessToken = null; if (is_object($response) && isset($response->access_token)) { $accessToken = $response->access_token; } elseif (is_array($response) && isset($response['access_token'])) { $accessToken = $response['access_token']; } if (isset($accessToken)) { return new FacebookSession($accessToken); } } return null; }
/** * Handles a response from Facebook, including a CSRF check, and returns a * FacebookSession. * * @return FacebookSession|null */ public function getSessionFromRedirect() { $this->loadState(); if ($this->isValidRedirect()) { $params = array('client_id' => FacebookSession::_getTargetAppId($this->appId), 'redirect_uri' => $this->redirectUrl, 'client_secret' => FacebookSession::_getTargetAppSecret($this->appSecret), 'code' => $this->getCode()); $fbRequest = new FacebookRequest(FacebookSession::newAppSession($this->appId, $this->appSecret), 'GET', '/oauth/access_token', $params); $response = $fbRequest->execute()->getResponse(); // echo __METHOD__ . __LINE__ . " Facebook Authentication response <br><pre>";var_dump($response);echo "</pre><br>"; if (isset($response['access_token'])) { return new FacebookSession($response['access_token']); } } return null; }