function loginFinish()
{
$helper = $this->api->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch (Facebook\Exceptions\FacebookResponseException $e) {
throw new Hybrid_Exception('Facebook Graph returned an error: ' . $e->getMessage());
} catch (Facebook\Exceptions\FacebookSDKException $e) {
throw new Hybrid_Exception('Facebook SDK returned an error: ' . $e->getMessage());
}
if (!isset($accessToken)) {
if ($helper->getError()) {
throw new Hybrid_Exception(sprintf("Could not authorize user, reason: %s (%d)", $helper->getErrorDescription(), $helper->getErrorCode()));
} else {
throw new Hybrid_Exception("Could not authorize user. Bad request");
}
}
try {
// Validate token
$oAuth2Client = $this->api->getOAuth2Client();
$tokenMetadata = $oAuth2Client->debugToken($accessToken);
$tokenMetadata->validateAppId($this->config["keys"]["id"]);
$tokenMetadata->validateExpiration();
// Exchanges a short-lived access token for a long-lived one
if (!$accessToken->isLongLived()) {
$accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
}
} catch (FacebookSDKException $e) {
throw new Hybrid_Exception($e->getMessage(), 0, $e);
}
$this->setUserConnected();
$this->token("access_token", $accessToken->getValue());
}