当前位置: 首页>>代码示例>>PHP>>正文


PHP FacebookRedirectLoginHelper::getSessionFromRedirect方法代码示例

本文整理汇总了PHP中Facebook\FacebookRedirectLoginHelper::getSessionFromRedirect方法的典型用法代码示例。如果您正苦于以下问题:PHP FacebookRedirectLoginHelper::getSessionFromRedirect方法的具体用法?PHP FacebookRedirectLoginHelper::getSessionFromRedirect怎么用?PHP FacebookRedirectLoginHelper::getSessionFromRedirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Facebook\FacebookRedirectLoginHelper的用法示例。


在下文中一共展示了FacebookRedirectLoginHelper::getSessionFromRedirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: obtainToken

 public function obtainToken($callback)
 {
     $helper = new FacebookRedirectLoginHelper($callback);
     if ($this->input->get('code') === null) {
         /**
          * Required permissions
          * public_profile
          * email
          * read_insights		Show analytics data of page in dashboard
          * read_page_mailboxes	Manage page conversations
          * read_mailbox			Manage page mailbox
          * manage_pages			Manage brand pages
          * publish_pages		Take actions on behalf of page
          */
         $loginUrl = $helper->getLoginUrl(array('public_profile', 'user_friends', 'email', 'read_mailbox', 'read_page_mailboxes', 'manage_pages', 'publish_actions', 'publish_pages', 'read_insights'));
         Url::redirect($loginUrl);
         return null;
     } else {
         $session = null;
         try {
             $session = $helper->getSessionFromRedirect();
         } catch (FacebookRequestException $ex) {
             // When Facebook returns an error
         } catch (\Exception $ex) {
             // When validation fails or other local issues
         }
         if ($session) {
             // Logged in
         }
         return $session;
     }
 }
开发者ID:ravikathaitarm01,项目名称:fluenz1,代码行数:32,代码来源:SDK.php

示例2: handle_fb_callback

function handle_fb_callback()
{
    render_boilerplate();
    $helper = new FacebookRedirectLoginHelper(MY_URL . 'fb_callback/');
    try {
        $session = $helper->getSessionFromRedirect();
    } catch (FacebookRequestException $ex) {
        // When Facebook returns an error
        Flight::error($ex);
    } catch (\Exception $ex) {
        // When validation fails or other local issues
        Flight:
        error($ex);
    }
    if ($session) {
        $_SESSION['FBTOKEN'] = $session->getToken();
        if (check_permissions($session)) {
            $_SESSION['FB_CHECKIN_NONCE'] = make_nonce();
            Flight::render('fb_callback', array('post_action' => MY_URL . 'checkin', 'place_name' => PAGE_NAME, 'nonce' => $_SESSION['FB_CHECKIN_NONCE']));
        } else {
            if (ARRAY_KEY_EXISTS('FB_REREQUEST', $_SESSION) && $_SESSION['FB_REREQUEST']) {
                Flight::render('denied_fb', array('msg' => _('You didn\'t grant us permission to post on Facebook. That\'s ok!')));
            } else {
                $_SESSION['FB_REREQUEST'] = True;
                Flight::redirect(MY_URL . 'rerequest_permission');
            }
        }
    } else {
        Flight::render('denied_fb', array('msg' => _('It looks like you didn\'t login! That\'s ok!')));
    }
}
开发者ID:monat78,项目名称:fbwlan,代码行数:31,代码来源:fb_handlers.php

示例3: action_index

 public function action_index()
 {
     try {
         $helper = new FacebookRedirectLoginHelper(Config::get('login_url'));
         $session = $helper->getSessionFromRedirect();
     } catch (FacebookRequestException $ex) {
         // When Facebook returns an error
     } catch (\Exception $ex) {
         // When validation fails or other local issues
     }
     if (isset($session)) {
         //login succes
         $long_lived_session = $session->getLongLivedSession();
         $access_token = $long_lived_session->getToken();
         //*** Call api to get user info
         $user_info = $this->facebook->get_user_information($access_token);
         //*** Check if user has existed
         $user = Model_Users::find('first', array('where' => array('fb_id' => $user_info->getId())));
         if (empty($user)) {
             // Register user
             if (Model_Users::register_user($user_info, $access_token)) {
                 //Success
             }
         }
         //*** Set session for user
         Fuel\Core\Session::set('user_token', $long_lived_session->getToken());
         Fuel\Core\Session::set('user_id', $user_info->getId());
         //*** Redirect to home
         \Fuel\Core\Response::redirect('fanpage/index');
     } else {
         // login fail
         $this->template->login_url = $helper->getLoginUrl();
     }
 }
开发者ID:nguyen-phuoc-mulodo,项目名称:mfb_fuel,代码行数:34,代码来源:login.php

示例4: apiAction

 /**
  * @Route("/fb")
  */
 public function apiAction()
 {
     // ustawiamy ID aplikacji i client secret
     FacebookSession::setDefaultApplication(FB_APP_ID, FB_APP_SECRET);
     // tworzymy helpera do zalogowania się
     $helper = new FacebookRedirectLoginHelper(FB_APP_REDIRECT_URI);
     // Pobieramy token sesji
     try {
         $session = $helper->getSessionFromRedirect();
         // Logowanie...
     } catch (FacebookRequestException $ex) {
         // jeśli błąd Facebooka
     } catch (\Exception $ex) {
         // jeśli ogólnie błąd
     }
     if ($session) {
         // Zalogowany
         echo 'Logged';
         // pobieramy profil zalogowanego użytkownika
         $user_profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
         // obiekt z danymi zalogowanego użytkownika:
         var_dump($user_profile);
     } else {
         // Link do logowania
         echo '<a href="' . $helper->getLoginUrl(array('email', 'user_friends')) . '">Login</a>';
     }
     return $this->render('Api/api.html.twig');
 }
开发者ID:KrzysztofSpetkowski,项目名称:GraphApi,代码行数:31,代码来源:ApiController.php

示例5: facebook

 public function facebook()
 {
     if (Session::has('flash_notification.message')) {
         return view('auth.facebook');
     }
     $config = config('services.facebook');
     session_start();
     FacebookSession::setDefaultApplication($config['id'], $config['secret']);
     $helper = new FacebookRedirectLoginHelper(route('facebook'));
     if (!Input::has('code')) {
         return redirect($helper->getLoginUrl(['email']));
     }
     try {
         $session = $helper->getSessionFromRedirect();
         $profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
     } catch (FacebookRequestException $e) {
         flash('Ne pare rău dar a apărut o eroare. <a href="' . route('facebook') . '">Încearcă din nou</a>.', 'danger');
         return redirect()->route('facebook');
     }
     if ($user = $this->userRepo->getByFacebook($profile->getId())) {
         return $this->loginUser($user);
     }
     if (empty($profile->getProperty('email'))) {
         flash('<p>Nu am putut citi adresa de email asociată contului tău de Facebook.</p> <p>Va trebui să te <a href="' . route('register') . '">înregistezi</a> pe site cu o adresă de email validă</p>', 'danger');
         return redirect()->route('facebook');
     }
     if ($this->userRepo->getByEmail($profile->getProperty('email'))) {
         flash('<p>Adresa de email asociată contului tău de Facebook este deja folosită pe site de altcineva.</p> <p>Va trebui să te <a href="' . route('register') . '">înregistezi</a> pe site cu o altă adresă de email.</p>', 'danger');
         return redirect()->route('facebook');
     }
     $user = User::create(['email' => $profile->getProperty('email'), 'first_name' => $profile->getFirstName(), 'last_name' => $profile->getLastName(), 'avatar' => $this->getFacebookPictureUrl($session), 'role_id' => config('auth.default_role_id'), 'confirmed' => 1, 'county_id' => 20]);
     $user->setMeta('facebook', $profile->getId());
     $user->save();
     return $this->loginUser($user);
 }
开发者ID:adriancatalinsv,项目名称:fiip,代码行数:35,代码来源:OAuthController.php

示例6: connect

 /**
  * @param $redirect_url
  * @return string|Facebook\GraphUser Login URL or GraphUser
  */
 function connect($redirect_url)
 {
     FacebookSession::setDefaultApplication($this->appId, $this->appSecret);
     $helper = new FacebookRedirectLoginHelper($redirect_url);
     if (isset($_SESSION) && isset($_SESSION['fb_token'])) {
         $session = new FacebookSession($_SESSION['fb_token']);
     } else {
         $session = $helper->getSessionFromRedirect();
     }
     if ($session) {
         try {
             $_SESSION['fb_token'] = $session->getToken();
             $request = new FacebookRequest($session, 'GET', '/me');
             $profile = $request->execute()->getGraphObject('Facebook\\GraphUser');
             if ($profile->getEmail() === null) {
                 throw new \Exception('L\'email n\'est pas disponible');
             }
             return $profile;
         } catch (\Exception $e) {
             unset($_SESSION['fb_token']);
             return $helper->getReRequestUrl(['email']);
         }
     } else {
         return $helper->getLoginUrl(['email']);
     }
 }
开发者ID:rizof,项目名称:Laravel-conexion,代码行数:30,代码来源:ConnexionFacebook.php

示例7: login

 /**
  * login with facebook sdk
  *
  * @param String $appId, $appSecret, $redirectUrl
  *
  * @return boolean
  */
 public function login($appId, $appSecret, $redirectUrl)
 {
     $redirectUrl = 'http://' . $_SERVER['HTTP_HOST'] . $redirectUrl;
     $request = new Request();
     FacebookSession::setDefaultApplication($appId, $appSecret);
     $helper = new FacebookRedirectLoginHelper($redirectUrl);
     try {
         $session = $helper->getSessionFromRedirect();
     } catch (FacebookRequestException $ex) {
         // When Facebook returns an error
     } catch (\Exception $ex) {
         // When validation fails or other local issues
     }
     $this->loginurl = $helper->getLoginUrl();
     if ($session) {
         $FacebookRequest = new FacebookRequest($session, 'GET', '/me');
         $response = $FacebookRequest->execute();
         $graph = $response->getGraphObject(GraphUser::classname());
         $name = $graph->getName();
         $accessToken = $session->getAccessToken();
         $request->setSession('facebook', (string) $accessToken);
         return true;
     } else {
         return false;
     }
 }
开发者ID:Juli55,项目名称:mvc-framework,代码行数:33,代码来源:FacebookLogin.php

示例8: facebokLoginHelper

 public function facebokLoginHelper($redirect_url, $canvas = false)
 {
     if ($canvas) {
         $helper = new FacebookCanvasLoginHelper();
     } else {
         $helper = new FacebookRedirectLoginHelper($redirect_url);
     }
     //missing javascript helper to be added in other relase
     // log errors
     try {
         $session = $helper->getSessionFromRedirect();
     } catch (FacebookRequestException $ex) {
         // When Facebook returns an error
         Log::error('Something is wrong from facebook.');
         return false;
     } catch (\Exception $ex) {
         // When validation fails or other local issues
         Log::error('Something is wrong with your user validation.');
         return false;
     }
     // work with the session
     if ($session) {
         return $session;
     } else {
         //return false to trigger redirect to facebook
         return false;
     }
 }
开发者ID:nobox,项目名称:identichip,代码行数:28,代码来源:Facebook.php

示例9: getUserInfo

 private function getUserInfo()
 {
     FacebookSession::setDefaultApplication(Config::get('facebook.appid'), Config::get('facebook.secret'));
     $helper = new FacebookRedirectLoginHelper('http://localhost:8000/home');
     $userID = "";
     $userEmail = "";
     $userName = "";
     $userPicUrl = "";
     try {
         $session = $helper->getSessionFromRedirect();
     } catch (FacebookRequestException $ex) {
         // When Facebook returns an error
     } catch (\Exception $ex) {
         // When validation fails or other local issues
     }
     if (isset($_SESSION['token'])) {
         // We have a token, is it valid?
         $session = new FacebookSession($_SESSION['token']);
         try {
             $session->Validate(Config::get('facebook.appid'), Config::get('facebook.secret'));
         } catch (FacebookAuthorizationException $ex) {
             // Session is not valid any more, get a new one.
             $session = '';
         }
     }
     if (isset($session)) {
         $_SESSION['token'] = $session->getToken();
         $request = new FacebookRequest($session, 'GET', '/me?fields=id,name,email,picture');
         $response = $request->execute();
         $graphObject = $response->getGraphObject();
         $userID = $graphObject->getProperty('id');
         $userName = $graphObject->getProperty('name');
         $userEmail = $graphObject->getProperty('email');
         $userPicObj = $graphObject->getProperty('picture')->asArray();
         $userPicUrl = $userPicObj['url'];
         $_SESSION['usrID'] = $userID;
         $_SESSION['usrName'] = $userName;
         $_SESSION['usrEmail'] = $userEmail;
         $_SESSION['usrPicUrl'] = $userPicUrl;
         $user_model = App\user::where('user_id', $userID)->first();
         if (is_null($user_model)) {
             $user_model = new App\user();
             $user_model->user_id = $userID;
             $user_model->user_name = $userName;
             $user_model->user_email = $userEmail;
             $user_model->user_profilePic = $userPicUrl;
             $user_model->save();
         } else {
             $user_model->user_name = $userName;
             $user_model->user_email = $userEmail;
             $user_model->user_profilePic = $userPicUrl;
             $user_model->save();
         }
     }
     $data = array("user_id" => $userID, "user_name" => $userName, "user_email" => $userEmail, "user_profilePic" => $userPicUrl);
     $data = array("user_id" => $userID, "user_name" => $userName, "user_email" => $userEmail, "user_profilePic" => $userPicUrl);
     return $data;
 }
开发者ID:CoffeeOwl17,项目名称:HEXA,代码行数:58,代码来源:HomeController.php

示例10: getSessionOnLogin

 /**
  * Get the Facebook session on redirect
  * @return bool|Facebook\FacebookSession
  */
 function getSessionOnLogin()
 {
     $helper = new Facebook\FacebookRedirectLoginHelper(\Idno\Core\site()->config()->getDisplayURL() . 'facebook/callback');
     try {
         return $helper->getSessionFromRedirect();
     } catch (\Exception $e) {
         return false;
     }
 }
开发者ID:kylewm,项目名称:KnownFacebook,代码行数:13,代码来源:FacebookAPI.php

示例11: facebook

 public function facebook()
 {
     $facebook_default_scope = explode(',', $this->ci->config->item("facebook_default_scope"));
     $facebook_app_id = $this->ci->config->item("facebook_app_id");
     $facebook_api_secret = $this->ci->config->item("facebook_api_secret");
     // init app with app id and secret
     FacebookSession::setDefaultApplication($facebook_app_id, $facebook_api_secret);
     // login helper with redirect_uri
     $helper = new FacebookRedirectLoginHelper(site_url('login/facebook'));
     // see if a existing session exists
     if (isset($_SESSION) && isset($_SESSION['fb_token'])) {
         // create new session from saved access_token
         $session = new FacebookSession($_SESSION['fb_token']);
         // validate the access_token to make sure it's still valid
         try {
             if (!$session->validate()) {
                 $session = null;
             }
         } catch (Exception $e) {
             // catch any exceptions
             $session = null;
         }
     }
     if (!isset($session) || $session === null) {
         // no session exists
         try {
             $session = $helper->getSessionFromRedirect();
         } catch (FacebookRequestException $ex) {
             // When Facebook returns an error
             // handle this better in production code
             print_r($ex);
         } catch (Exception $ex) {
             // When validation fails or other local issues
             // handle this better in production code
             print_r($ex);
         }
     }
     // see if we have a session
     if (isset($session)) {
         // save the session
         $_SESSION['fb_token'] = $session->getToken();
         // create a session using saved token or the new one we generated at login
         $session = new FacebookSession($session->getToken());
         // graph api request for user data
         //$request = new FacebookRequest($session, 'GET', '/me/friends');
         $request = new FacebookRequest($session, 'GET', '/me?fields=id,name,picture,friends');
         $response = $request->execute();
         // get response
         $graphObject = $response->getGraphObject()->asArray();
         $fb_data = array('me' => $graphObject, 'loginUrl' => $helper->getLoginUrl($facebook_default_scope));
         $this->ci->session->set_userdata('fb_data', $fb_data);
     } else {
         $fb_data = array('me' => null, 'loginUrl' => $helper->getLoginUrl($facebook_default_scope));
         $this->ci->session->set_userdata('fb_data', $fb_data);
     }
     return $fb_data;
 }
开发者ID:ponchov,项目名称:quizzworld,代码行数:57,代码来源:lib_login.php

示例12: handleCallback

 /**
  * Handles the Facebook callback request
  */
 public function handleCallback()
 {
     try {
         $this->facebookSession = $this->loginHelper->getSessionFromRedirect();
         Session::put('fb_token', $this->facebookSession->getToken());
         return TRUE;
     } catch (FacebookRequestException $e) {
         throw new PhacebookException($e->getMessage());
     }
 }
开发者ID:zolli,项目名称:phacebook,代码行数:13,代码来源:Phacebook.php

示例13: facebookConnect

/**
 * This function connect to facebook and retrieves the user info
 * If user does not exist in chamilo, it creates it and logs in
 * If user already exists, it updates his info
 */
function facebookConnect()
{
    global $facebook_config;
    global $helper;
    try {
        $helper = new FacebookRedirectLoginHelper($facebook_config['return_url']);
        $session = $helper->getSessionFromRedirect();
        // see if we have a session
        if (isset($session)) {
            // graph api request for user data
            $request = new FacebookRequest($session, 'GET', '/me');
            $response = $request->execute();
            // get response
            $graphObject = $response->getGraphObject();
            $username = changeToValidChamiloLogin($graphObject->getProperty('email'));
            $email = $graphObject->getProperty('email');
            $locale = $graphObject->getProperty('locale');
            $language = facebookPluginGetLanguage($locale);
            if (!$language) {
                $language = 'en_US';
            }
            //Checks if user already exists in chamilo
            $u = array('firstname' => $graphObject->getProperty('first_name'), 'lastname' => $graphObject->getProperty('last_name'), 'status' => STUDENT, 'email' => $graphObject->getProperty('email'), 'username' => $username, 'language' => $language, 'password' => 'facebook', 'auth_source' => 'facebook', 'extra' => array());
            $chamiloUinfo = api_get_user_info_from_email($email);
            if ($chamiloUinfo === false) {
                // we have to create the user
                $chamilo_uid = external_add_user($u);
                if ($chamilo_uid !== false) {
                    $_user['user_id'] = $chamilo_uid;
                    $_user['uidReset'] = true;
                    $_SESSION['_user'] = $_user;
                    header('Location:' . api_get_path(WEB_PATH));
                    exit;
                } else {
                    return false;
                }
            } else {
                // User already exists, update info and login
                $chamilo_uid = $chamiloUinfo['user_id'];
                $u['user_id'] = $chamilo_uid;
                external_update_user($u);
                $_user['user_id'] = $chamilo_uid;
                $_user['uidReset'] = true;
                $_SESSION['_user'] = $_user;
                header('Location:' . api_get_path(WEB_PATH));
                exit;
            }
        }
    } catch (FacebookRequestException $ex) {
        echo $ex;
    } catch (Exception $ex) {
        // When validation fails or other local issues
    }
}
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:59,代码来源:facebook.inc.php

示例14: facebook_helper

 public function facebook_helper()
 {
     $redirectUrl = $this->facebook["callback_url"];
     $helper = new FacebookRedirectLoginHelper($redirectUrl);
     try {
         $session = $helper->getSessionFromRedirect();
     } catch (FacebookSDKException $e) {
         $session = null;
     }
     return compact('helper', 'session');
 }
开发者ID:franky0930,项目名称:MarketingConnex,代码行数:11,代码来源:SocialmediaComponent.php

示例15: getConfigChannel

 public function getConfigChannel($id)
 {
     session_start();
     $ch = Helper::getChannel($id);
     // FACEBOOK
     if ($ch->type == 'f') {
         if (!$ch) {
             return "Canal no encontrado";
         }
         if (Input::get('code')) {
             FacebookSession::setDefaultApplication($ch->getParam('APP_ID'), $ch->getParam('APP_SECRET'));
             $helper = new FacebookRedirectLoginHelper(URL::to('social/config/channel/' . $id));
             $session = $helper->getSessionFromRedirect();
             if ($session->validate()) {
                 $request = new FacebookRequest($session, 'GET', '/me/accounts?fields=name,access_token,perms');
                 $pageList = $request->execute()->getGraphObject()->asArray();
                 if ($ch->getParam('PAGE_ID')) {
                     //Comprobamos que la pagina que hemos introducido esta entre las que administra el usuario
                     $page = Facebook::checkIdPage($ch->getParam('PAGE_ID'), $pageList['data']);
                     if ($page) {
                         $ch->setParam('TOKEN', $page->access_token);
                         $ch->setParam('PAGE_NAME', $page->name);
                         return Redirect::to('social/config/channel/' . $id)->with('message', 'Canal configurado con exito , Página ' . $page->name);
                     }
                 }
                 return Redirect::to('social/config/channel/' . $id)->with('error', 'Debe introducir el id de la pagina con la cuel quiere publicar');
             }
         }
         if ($ch->getParam('TOKEN')) {
             // $ch->getTokenInfo();
         }
     }
     // !!
     // TWITTER
     if ($ch->type == 't') {
         //          try{
         //
         //           // $res = file_get_contents('http://tinyurl.com/api-create.php?url=http://stackoverflow.com/questions/22355828/doing-http-requests-from-laravel-to-an-external-api');
         //            //$uploaded_media = Social::Twitter()->uploadMedia(['media' => File::get(public_path('front/images/vilca_logo4.png'))]);
         //            //$res=Social::Twitter()->postTweet(['status' => ' defg  ,jh efg  ,jh  defg  ,jh  defg   defg  ,jh  defg  ,jh  defg  ,j fin '.$res, 'media_ids' => $uploaded_media->media_id_string]);;
         //          //  var_dump( Social::Twitter()->getUserTimeline(['screen_name' => 'thujohn', 'count' => 1, 'format' => 'json'])
         //          );
         //          }catch (\Exception $e){
         //
         //              return Redirect::back()->with('error',$e->getMessage());
         //          }
         // $cfg_tw=Config::get('social.twitter');
     }
     $tmp = array('extends' => Config::get('social::social.tmp.admin', 'layout.base'), 'section_main' => Config::get('social::social.tmp.section_main', 'main'));
     $header_title = array('clase' => 'fa fa-share-alt', 'titulo' => 'Social <small>Config::' . $ch->description . '</small>');
     return View::make('social::configChannel', compact('ch', 'tmp', 'header_title'));
 }
开发者ID:jsehersan,项目名称:social,代码行数:52,代码来源:ConfigController.php


注:本文中的Facebook\FacebookRedirectLoginHelper::getSessionFromRedirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。