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


PHP Facebook\FacebookSession类代码示例

本文整理汇总了PHP中Facebook\FacebookSession的典型用法代码示例。如果您正苦于以下问题:PHP FacebookSession类的具体用法?PHP FacebookSession怎么用?PHP FacebookSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: 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

示例2: 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

示例3: exchange_long_lived_token

 public function exchange_long_lived_token($access_token)
 {
     $session = new FacebookSession($access_token);
     // Check validate token
     if ($session->validate()) {
         $long_lived_session = $session->getLongLivedSession();
         return $long_lived_session->getToken();
     }
     return false;
 }
开发者ID:nguyen-phuoc-mulodo,项目名称:mfb_fuel,代码行数:10,代码来源:facebook.php

示例4: isLogged

function isLogged()
{
    // Inicializações para autenticação
    // Crie um aplicativo no Facebook e configure aqui o ID e a chave secreta obtidos no site
    $id = '987654321012345';
    $secret = 'aeiou12345qwert98765asdfg1234567';
    FacebookSession::setDefaultApplication($id, $secret);
    // Inicializa sessão PHP
    session_start();
    // Se o cookie foi recebido numa requisição anterior, e o
    // token FB já foi recuperado, necessita apenas autenticar
    // o usuário no FB usando o token
    if (isset($_SESSION['token'])) {
        $session = new FacebookSession($_SESSION['token']);
        try {
            if (!$session->validate($id, $secret)) {
                unset($session);
            }
        } catch (FacebookRequestException $ex) {
            // Facebook retornou um erro
            // return [false, $ex->getMessage()];
            unset($session);
        } catch (\Exception $ex) {
            // return [false, $ex->getMessage()];
            unset($session);
        }
    }
    // Se o cookie ainda não foi recebido (primeira requisição
    // do cliente), recupera e grava na variável de sessão PHP.
    // Executa autenticação no FB
    if (!isset($session)) {
        try {
            $helper = new FacebookJavaScriptLoginHelper();
            $session = $helper->getSession();
            if ($session) {
                $_SESSION['token'] = $session->getToken();
            }
        } catch (FacebookRequestException $ex) {
            // Facebook retornou um erro
            unset($session);
            return [false, $ex->getMessage()];
        } catch (\Exception $ex) {
            // Falha na validação ou outro erro
            unset($session);
            return [false, $ex->getMessage()];
        }
    }
    // Facebook aceitou usuário/senha
    if (isset($session) && $session) {
        return [true, $_SESSION['token']];
    }
    // Facebook rejeitou usuário/senha
    return [false, "Usuário/senha inválida"];
}
开发者ID:kwdeveloper,项目名称:crie-app-web,代码行数:54,代码来源:auth.php

示例5: validate

 public function validate()
 {
     try {
         FacebookSession::setDefaultApplication($this->getParam('APP_ID'), $this->getParam('APP_SECRET'));
         $session = new FacebookSession($this->getParam('TOKEN'));
         $session->validate();
     } catch (FacebookSDKException $f) {
         return false;
     }
     return true;
 }
开发者ID:jsehersan,项目名称:social,代码行数:11,代码来源:Facebook.php

示例6: getFacebookSession

 /**
  * Get the FacebookSession through an access_token.
  *
  * @param  string $accessToken
  * @return FacebookSession
  */
 private function getFacebookSession($accessToken)
 {
     $facebookSession = new FacebookSession($accessToken);
     try {
         $facebookSession->validate();
         return $facebookSession;
     } catch (FacebookRequestException $ex) {
         throw new FacebookException($ex->getMessage());
     } catch (\Exception $ex) {
         throw new FacebookException($ex->getMessage());
     }
 }
开发者ID:welderlourenco,项目名称:laravel-facebook,代码行数:18,代码来源:Facebook.php

示例7: connect

 /**
  * @param string $accessToken
  * @param string $appId
  * @param string $appSecret
  * @throws \Vegas\Social\Exception
  */
 protected function connect($accessToken, $appId, $appSecret)
 {
     $session = new FacebookSession($accessToken);
     $session->setDefaultApplication($appId, $appSecret);
     if ($session->getToken() == $accessToken) {
         $this->fbSession = $session;
         $this->fbScope = $session->getSessionInfo()->getScopes();
         $this->checkPermissions();
         return $this;
     }
     $this->fbSession = false;
     throw new \Vegas\Social\Exception\InvalidSessionException();
 }
开发者ID:vegas-cmf,项目名称:social,代码行数:19,代码来源:Service.php

示例8: initialize

 /**
  * Initializes facebook's connection.
  *
  * @throws FacebookRequestException
  * @throws \Exception
  */
 private function initialize()
 {
     FacebookSession::enableAppSecretProof(false);
     $session = new FacebookSession($this->accessToken);
     try {
         $session->validate();
     } catch (FacebookRequestException $e) {
         $this->entry->addException($e->getMessage());
     } catch (\Exception $e) {
         $this->entry->addException($e->getMessage());
     }
     $this->session = $session;
 }
开发者ID:crashev,项目名称:DataAggregator,代码行数:19,代码来源:FacebookProvider.php

示例9: matchUser

 public function matchUser($access_token)
 {
     FacebookSession::setDefaultApplication('1594113490874544', 'fca50280932a6065e68a540ac3f2925b');
     $session = new FacebookSession($access_token);
     try {
         $session->validate();
     } catch (FacebookRequestException $ex) {
         return false;
     } catch (\Exception $ex) {
         return false;
     }
     return true;
 }
开发者ID:nadiTime,项目名称:musicstore,代码行数:13,代码来源:FBLogin.class.php

示例10: getFacebookSession

 /**
  * Get the FacebookSession through an access_token.
  *
  * @param string $accessToken
  * @return FacebookSession
  */
 public function getFacebookSession($accessToken)
 {
     $session = new FacebookSession($accessToken);
     // 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;
     }
     return $session;
 }
开发者ID:gponster,项目名称:laravel-facebook-sdk,代码行数:20,代码来源:Facebook.php

示例11: loginFacebookAction

 public function loginFacebookAction()
 {
     $response = array("status" => 0, "message" => "Thao tác không thành công");
     if (!empty($this->user)) {
         $response["status"] = 1;
     } else {
         if ($this->request->isPost()) {
             $acesstoken = $this->request->getPost("accesstoken", null, false);
             \Facebook\FacebookSession::setDefaultApplication($this->config["FACEBOOK_ID"], $this->config["FACEBOOK_SECRET"]);
             $session = new \Facebook\FacebookSession($acesstoken);
             if ($session) {
                 $user_profile = (new \Facebook\FacebookRequest($session, 'GET', '/me', ['fields' => 'id,name,email']))->execute()->getGraphObject(\Facebook\GraphUser::className());
                 if (!empty($user_profile)) {
                     $email = $user_profile->getEmail();
                     $id = $user_profile->getId();
                     $username = explode("@", $email);
                     $username = $username[0] . "_fb_" . $id;
                     $data_user = array("email" => $email, "nickname" => $user_profile->getName(), "username" => $username, "id" => $id);
                     $response = $this->doSocialLogin($data_user);
                 }
             }
         }
     }
     echo json_encode($response);
     exit;
 }
开发者ID:nbtai,项目名称:haiquan,代码行数:26,代码来源:UserController.php

示例12: BuildLink

 public function BuildLink($params = null)
 {
     require_once 'Facebook/FacebookSDKException.php';
     $APP_ID = $this->GetClientId();
     $APP_SECRET = $this->GetClientSecret();
     if (!isset($APP_ID) || !isset($APP_SECRET)) {
         throw new \Facebook\FacebookSDKException('You must to set the app client credentials');
     }
     require_once 'Facebook/FacebookSession.php';
     \Facebook\FacebookSession::setDefaultApplication($APP_ID, $APP_SECRET);
     $CALLBACK_URL = $this->GetCallbackUrl();
     if (!isset($CALLBACK_URL)) {
         throw new \Facebook\FacebookSDKException('You must to set callback url');
     }
     $SCOPE = $this->GetScope();
     if (!isset($SCOPE)) {
         throw new \Facebook\FacebookSDKException('You must to set scope');
     }
     require_once 'Facebook/FacebookRequest.php';
     require_once 'Facebook/FacebookRedirectLoginHelper.php';
     $helper = new \Facebook\FacebookRedirectLoginHelper($CALLBACK_URL);
     $STATE = $this->GetState();
     if (isset($STATE)) {
         $helper->SetState($STATE);
     }
     $redirectUrl = $helper->getLoginUrl($SCOPE);
     //	var_dump($redirectUrl);
     return $redirectUrl;
 }
开发者ID:avassilenko,项目名称:av_2,代码行数:29,代码来源:FacebookSignUpLinkController.php

示例13: getSession

 /**
  * @return \Facebook\FacebookSession
  */
 public function getSession()
 {
     $conf = json_decode(file_get_contents(realpath(dirname(__FILE__)) . '/config.json'));
     Api::init($conf->applicationId, $conf->applicationSecret, $conf->accessToken);
     FacebookSession::setDefaultApplication($conf->applicationId, $conf->applicationSecret);
     return new FacebookSession($conf->accessToken);
 }
开发者ID:shmurakami,项目名称:facebook-object,代码行数:10,代码来源:TestBase.php

示例14: getSession

 /**
  * @return FacebookSession
  */
 protected function getSession()
 {
     if (!$this->session) {
         $this->session = FacebookSession::newAppSession();
     }
     return $this->session;
 }
开发者ID:bzis,项目名称:zomba,代码行数:10,代码来源:FacebookApiProvider.php

示例15: register

 public function register($kernel, $options = array())
 {
     FacebookSession::setDefaultApplication($options['AppId'], $options['AppSecret']);
     $kernel->facebookSession = function () use($options) {
         return FacebookSession::newAppSession();
     };
 }
开发者ID:azole,项目名称:Phifty,代码行数:7,代码来源:Facebook4Service.php


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