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


PHP FacebookSession::validate方法代码示例

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


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

示例1: connect

 /**
  * @param string $accessToken
  *
  * @throws FacebookException
  */
 public function connect($accessToken)
 {
     $this->session = new FacebookSession($accessToken);
     try {
         $this->session->validate();
     } catch (FacebookRequestException $exception) {
         // Session not valid, Graph API returned an exception with the reason.
         throw new FacebookException($exception->getMessage());
     } catch (\Exception $exception) {
         // Graph API returned info, but it may mismatch the current app or have expired.
         throw new FacebookException($exception->getMessage());
     }
 }
开发者ID:oriodesign,项目名称:tastd-backend-demo,代码行数:18,代码来源:FacebookClient.php

示例2: hasLoggedIn

 /**
  * Ask for a facebook session 
  * @return boolean
  */
 public final function hasLoggedIn()
 {
     if (is_null($this->fbsession) and !is_null($this->session)) {
         return $this->session->getData("_facebookSession") ?: false;
     }
     return $this->fbsession->validate();
 }
开发者ID:diego3,项目名称:myframework-skeleton,代码行数:11,代码来源:FacebookService.php

示例3: tryValidateSession

 /**
  * Try tlo initialize FacebookSession with a providedd acces token
  *
  * @param String $accessToken Tha external accessToken
  * @throws Exceptions\PhacebookException
  */
 private function tryValidateSession($accessToken)
 {
     $this->facebookSession = new FacebookSession($accessToken);
     try {
         $this->facebookSession->validate();
     } catch (FacebookSDKException $e) {
         throw new PhacebookException($e->getMessage());
     }
 }
开发者ID:zolli,项目名称:phacebook,代码行数:15,代码来源:Phacebook.php

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

示例5: isLoggedIn

 public function isLoggedIn()
 {
     $logged = false;
     if (!empty($this->session)) {
         try {
             $this->session->validate();
             $logged = true;
         } catch (FacebookRequestException $ex) {
             // Session not valid, Graph API returned an exception with the reason.
             Log::warning($ex->getMessage());
         } catch (Exception $ex) {
             // Graph API returned info, but it may mismatch the current app or have expired.
             Log::warning($ex->getMessage());
         }
         return $logged;
     } else {
         return $logged;
     }
 }
开发者ID:jiqiang90,项目名称:laravel-restful-api-starter,代码行数:19,代码来源:FacebookWrapper.php

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

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

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

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

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

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

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

示例13: loginAction

 public function loginAction($appId, Request $request)
 {
     $ret = array('success' => false);
     if ($request->request->get('facebook_token') != null && 'POST' === $request->getMethod()) {
         $em = $this->getDoctrine();
         $app = $em->getRepository('KeosuCoreBundle:App')->find($appId);
         $configPackages = $app->getConfigPackages();
         $fbAppId = $configPackages[KeosuGadgetFaceBookBundle::PLUGIN_NAME]['fbAppId'];
         $fbAppSecret = $configPackages[KeosuGadgetFaceBookBundle::PLUGIN_NAME]['fbAppSecret'];
         FacebookSession::setDefaultApplication($fbAppId, $fbAppSecret);
         $session = new FacebookSession($request->request->get('facebook_token'));
         try {
             $session->validate();
             $user_profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className());
             // user Email
             $email = $user_profile->getProperty('email');
             $userManager = $this->container->get('fos_user.user_manager');
             $user = $userManager->findUserByUsernameOrEmail($email);
             // the user doesn't have account
             if ($user == null) {
                 $user = $userManager->createUser();
                 $user->setUsername($email);
                 $user->setEnabled(true);
                 $user->setPlainPassword(\md5($email . \rand()));
                 $user->setEmail($email);
                 $user->setAccountType('facebook');
                 $userManager->updateUser($user);
             }
             if ($user->getAccountType() == 'facebook') {
                 // We log the user
                 $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
                 $this->get('security.context')->setToken($token);
                 $this->get('session')->set('_security_main', serialize($token));
                 $ret['success'] = true;
             } else {
                 $ret['message'] = "This email is allready used with an other account";
             }
         } catch (FacebookRequestException $ex) {
             echo $ex->getMessage();
         } catch (\Exception $ex) {
             echo $ex->getMessage();
         }
     } else {
         $ret['message'] = 'unable to login with facebook';
     }
     return new JsonResponse($ret);
 }
开发者ID:predever,项目名称:keosu,代码行数:47,代码来源:ServiceController.php

示例14: facebook

 /**
  * @param string $accessToken
  * @return bool
  */
 public function facebook($accessToken = null)
 {
     if (empty($accessToken)) {
         return false;
     }
     FacebookSession::setDefaultApplication(Config::get('verify::facebook.appId'), Config::get('verify::facebook.appSecret'));
     $session = new FacebookSession($accessToken);
     try {
         $session->validate(Config::get('verify::facebook.appId'), Config::get('verify::facebook.appSecret'));
         $data = $session->getSessionInfo()->asArray();
         return array('valid' => true, 'user_id' => $data['user_id'], 'app_id' => $data['app_id'], 'message' => 'Access Token is valid.');
     } catch (FacebookRequestException $ex) {
         return array('valid' => false, 'messages' => $ex->getMessage());
     } catch (Exception $ex) {
         return array('valid' => false, 'messages' => $ex->getMessage());
     }
 }
开发者ID:hoangnham01,项目名称:verify,代码行数:21,代码来源:Verify.php

示例15: getSession

 private function getSession()
 {
     $token = get_option($this->tokenOptionsKey, "");
     $session = new FacebookSession($token);
     // To validate the session:
     try {
         $session->validate();
         return $session;
     } catch (FacebookRequestException $ex) {
         // Session not valid, Graph API returned an exception with the reason.
         echo $ex->getMessage();
         return null;
     } catch (\Exception $ex) {
         // Graph API returned info, but it may mismatch the current app or have expired.
         echo $ex->getMessage();
         return null;
     }
 }
开发者ID:maxijb,项目名称:social-fetcher,代码行数:18,代码来源:facebook-social-fetcher.php


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