• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Facebook\FacebookSession类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: action_index

 public function action_index()
 {
     $gameList = DB::query(Database::SELECT, "SELECT * FROM game")->execute();
     $this->template->content = $gameList[0]['name'];
     require_once Kohana::find_file('vendor', 'vendor/autoload');
     $config = Kohana::$config->load('auth');
     //$session = Session::instance($config['session_type']);
     FacebookSession::setDefaultApplication('376812619137510', 'd054fff7f6146da72c9585d78d0357b5');
     $helper = new FacebookJavaScriptLoginHelper();
     try {
         $session = $helper->getSession();
     } catch (FacebookRequestException $ex) {
         // When Facebook returns an error
         $this->template->content = "fb returned an error";
     } catch (\Exception $ex) {
         // When validation fails or other local issues
         $this->template->content = "validation failed";
         //print_r($ex);
     }
     if (isset($session)) {
         $request = new FacebookRequest($session, 'GET', '/me');
         $response = $request->execute();
         $graphObject = $response->getGraphObject();
         if (isset($graphObject->id)) {
             $loginData = array('first_name' => $graphObject->first_name);
         }
         $this->template->content = "Hi, " . $graphObject->getProperty('first_name');
     } else {
         echo "No session";
     }
 }
开发者ID:Xackery,项目名称:coop,代码行数:31,代码来源:Facebook.php


示例17: __construct

 public function __construct()
 {
     $this->ci =& get_instance();
     FacebookSession::setDefaultApplication($this->ci->config->item('api_id', 'facebook'), $this->ci->config->item('app_secret', 'facebook'));
     $this->helper = new FacebookRedirectLoginHelper($this->ci->config->item('redirect_url', 'facebook'));
     if ($this->ci->session->userdata('fb_token')) {
         $this->session = new FacebookSession($this->ci->session->userdata('fb_token'));
         // Validate the access_token to make sure it's still valid
         try {
             if (!$this->session->validate()) {
                 $this->session = false;
             }
         } catch (Exception $e) {
             // Catch any exceptions
             $this->session = false;
         }
     } else {
         try {
             $this->session = $this->helper->getSessionFromRedirect();
         } catch (FacebookRequestException $ex) {
             // When Facebook returns an error
         } catch (\Exception $ex) {
             // When validation fails or other local issues
         }
     }
     if ($this->session) {
         $this->ci->session->set_userdata('fb_token', $this->session->getToken());
         $this->session = new FacebookSession($this->session->getToken());
     }
 }
开发者ID:andrilGhiraldello,项目名称:Facebook-v4-PHP-CodeIgniter,代码行数:30,代码来源:Facebook.php


示例18: FacebookRedirectLoginHelper

 function __construct()
 {
     parent::__construct();
     $this->load->helper('form');
     $this->load->library('form_validation');
     $this->load->library('session');
     $this->load->library('email');
     $this->load->helper('url');
     $this->load->helper('cookie');
     $this->load->model('user_model');
     $this->load->model('user_cookie_model');
     // setting up email ===============================================
     $config['useragent'] = "Codeigniter";
     $config['protocol'] = "smtp";
     $config['smtp_host'] = "smtp.gmail.com";
     $config['smtp_port'] = "465";
     $config['smtp_user'] = "[email protected]";
     $config['smtp_pass'] = "henryA@2";
     $config['charset'] = "utf-8";
     $config['mailtype'] = "html";
     $config['newline'] = "\r\n";
     $config['smtp_crypto'] = "ssl";
     $this->email->initialize($config);
     $this->email->from('[email protected]', 'VN UP TEST');
     // ==================================================================
     $this->default_redirectURL = config_item('base_url') . 'user/user';
     FacebookSession::setDefaultApplication($this->app_id, $this->app_secret);
     $this->helper = new FacebookRedirectLoginHelper($this->default_redirectURL);
     $this->wp_hasher = new PasswordHash(8, true);
 }
开发者ID:RobertDuy,项目名称:vnup,代码行数:30,代码来源:User.php


示例19: getSession

 private function getSession()
 {
     $session = "";
     FacebookSession::setDefaultApplication(Config::get('facebook.appid'), Config::get('facebook.secret'));
     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 = '';
         }
     }
     return $session;
 }
开发者ID:CoffeeOwl17,项目名称:HEXA,代码行数:16,代码来源:PostController.php


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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Facebook\GraphUser类代码示例发布时间:2022-05-23
下一篇:
PHP Facebook\FacebookRequest类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap