/** * Returns the URL to send the user in order to log out of Facebook. * * @param FacebookSession $session The session that will be logged out * @param string $next The url Facebook should redirect the user to after * a successful logout * * @return string */ public function getLogoutUrl($session, $next) { $params = array('next' => $next, 'access_token' => $session->getToken()); return 'https://www.facebook.com/logout.php?' . http_build_query($params); }
/** * FacebookRequest - Returns a new request using the given session. optional * parameters hash will be sent with the request. This object is * immutable. * * @param FacebookSession $session * @param string $method * @param string $path * @param array|null $parameters * * @return FacebookRequest */ public function __construct($session, $method, $path, $parameters = null, $version = null) { $this->session = $session; $this->method = $method; $this->path = $path; if ($version) { $this->version = $version; } else { $this->version = static::GRAPH_API_VERSION; } $params = $parameters ?: array(); if ($session) { $params["access_token"] = $session->getToken(); } $this->params = $params; return $this; }
public function fb_login() { echo "sdxcxcfsdf"; echo "i am here"; $this->layout = 'ajax'; FacebookSession::setDefaultApplication('195891030745689', '130d8f7bcae67a9a71d2c1c372896814'); $helper = new FacebookRedirectLoginHelper(FACEBOOK_REDIRECT_URI); echo "======="; $session = $helper->getSessionFromRedirect(); if (isset($_SESSION['token'])) { pr($_SESSION); echo "<<<<<<>>>>>>"; $session = new FacebookSession($_SESSION['token']); try { echo "XXXXXXXXXX"; $session->validate(FACEBOOK_APP_ID, FACEBOOK_APP_SECRET); } catch (FacebookAuthorizationException $e) { echo $e->getMessage(); } } $data = array(); $fb_data = array(); if (isset($session)) { $_SESSION['token'] = $session->getToken(); $request = new FacebookRequest($session, 'GET', '/me'); $response = $request->execute(); $graph = $response->getGraphObject(GraphUser::className()); $fb_data = $graph->asArray(); $id = $graph->getId(); $image = "https://graph.facebook.com/" . $id . "/picture?width=100"; if (!empty($fb_data)) { $result = $this->User->findByEmail($fb_data['email']); if (!empty($result)) { if ($this->Auth->login($result['User'])) { $this->Session->setFlash(FACEBOOK_LOGIN_SUCCESS, 'default', array('class' => 'message success'), 'success'); //$this->redirect(BASE_PATH); } else { $this->Session->setFlash(FACEBOOK_LOGIN_FAILURE, 'default', array('class' => 'message error'), 'error'); //$this->redirect(BASE_PATH.'login'); } } else { $data['email'] = $fb_data['email']; $data['first_name'] = $fb_data['first_name']; $data['social_id'] = $fb_data['id']; $data['picture'] = $image; $data['uuid'] = String::uuid(); $this->User->save($data); if ($this->User->save($data)) { $data['id'] = $this->User->getLastInsertID(); if ($this->Auth->login($data)) { $this->Session->setFlash(FACEBOOK_LOGIN_SUCCESS, 'default', array('class' => 'message success'), 'success'); //$this->redirect(BASE_PATH); } else { $this->Session->setFlash(FACEBOOK_LOGIN_FAILURE, 'default', array('class' => 'message error'), 'error'); //$this->redirect(BASE_PATH.'index'); } } else { $this->Session->setFlash(FACEBOOK_LOGIN_FAILURE, 'default', array('class' => 'message error'), 'error'); //$this->redirect(BASE_PATH.'index'); } } } else { $this->Session->setFlash(FACEBOOK_LOGIN_FAILURE, 'default', array('class' => 'message error'), 'error'); //$this->redirect(BASE_PATH.'index'); } } }
/** * Returns the URL to send the user in order to log out of Facebook. * * @param FacebookSession $session The session that will be logged out * @param string $next The url Facebook should redirect the user to after * a successful logout * * @return string * * @throws FacebookSDKException */ public function getLogoutUrl(FacebookSession $session, $next) { if ($session->getAccessToken()->isAppSession()) { throw new FacebookSDKException('Cannot generate a Logout URL with an App Session.', 722); } $params = array('next' => $next, 'access_token' => $session->getToken()); return 'https://www.facebook.com/logout.php?' . http_build_query($params, null, '&'); }
/** * FacebookRequest - Returns a new request using the given session. optional * parameters hash will be sent with the request. This object is * immutable. * * @param FacebookSession $session * @param string $method * @param string $path * @param array|null $parameters * @param string|null $version * @param string|null $etag */ public function __construct($session, $method, $path, $parameters = null, $version = null, $etag = null) { $this->session = $session; $this->method = $method; $this->path = $path; if ($version) { $this->version = $version; } else { $this->version = static::GRAPH_API_VERSION; } $this->etag = $etag; //echo "<pre>";print_r($session->getToken()); echo "</pre>"; die; $params = $parameters ?: array(); if ($session && !isset($params["access_token"])) { $params["access_token"] = $session->getToken(); } if (FacebookSession::useAppSecretProof() && !isset($params["appsecret_proof"])) { $params["appsecret_proof"] = $this->getAppSecretProof($params["access_token"]); } $this->params = $params; }