/** * Getting token wth Grap Api * * @param $scope array * @param $redirectURl string * @return array */ public function getAccessToken($redirectURl, $scope = null) { if ($scope == '') { $scope = $this->allScope; } $helper = new \Facebook\FacebookRedirectLoginHelper($redirectURl); try { $tokenInfo = json_encode(file_get_contents('https://graph.facebook.com/oauth/access_token?' . http_build_query(array('client_id' => APP_ID, 'client_secret' => APP_SECRET, 'redirect_uri' => $redirectURl, 'code' => $_GET['code'])))); $token = explode("=", $tokenInfo); $response['tokenExpireTime'] = $token[2]; $key = explode("&expires", $token[1]); $response['token'] = $key[0]; $session = new \Facebook\FacebookSession($key[0]); $response['logoutURL'] = $helper->getLogoutUrl($session, $redirectURl); $response['status'] = true; return $response; } catch (Exception $e) { $response['exceptionCode'] = $e->getCode(); $response['exceptionMessage'] = $e->getMessage(); $response['loginURL'] = $helper->getLoginUrl($scope); $response['status'] = false; return $response; } }
/** * User-Logout * * @return bool */ public function logout() { $this->init_fb(); try { $helper = new Facebook\FacebookJavaScriptLoginHelper(); $session = $helper->getSession(); if ($session) { $me = $this->getMe($session); if ($me) { $helper = new Facebook\FacebookRedirectLoginHelper($this->env->link . $this->controller_path_plain); redirect($helper->getLogoutUrl($session, $this->env->link . $this->controller_path_plain . 'Login/Logout' . $this->routing->getSeoExtension() . $this->SID . '&link_hash=' . $this->user->csrfGetToken("login_pageobjectlogout")), false, true); } } } catch (Exception $e) { $this->core->message($e->getMessage(), "Facebook Exception logout()", 'red'); } return true; }