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


PHP FacebookSession::Validate方法代码示例

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


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

示例3: DateTime

         $dateNacimiento = new DateTime($cumple);
         $edad = $hoy->diff($dateNacimiento)->y;
         $response = array('nombre' => $nombre, 'cumpleanos' => $cumple, 'email' => $email, 'genero' => $genero, 'edad' => $edad);
     } else {
         $response = array('error' => 'error');
     }
     $respuestaJSON = json_encode($response);
     echo $respuestaJSON;
 }
 if ($peticion == "foto") {
     $helper = new FacebookJavaScriptLoginHelper();
     if (isset($_SESSION['token'])) {
         // We have a token, is it valid?
         $session = new FacebookSession($_SESSION['token']);
         try {
             $session->Validate($app_id, $app_secret);
         } catch (FacebookAuthorizationException $ex) {
             // Session is not valid any more, get a new one.
             $session = '';
         }
     }
     if (isset($session)) {
         $request = new FacebookRequest($session, 'GET', '/me');
         $response = $request->execute();
         $graphObject = $response->getGraphObject();
         $user = $response->getGraphObject(GraphUser::className());
         $userID = $user->getId();
         $link = 'http://graph.facebook.com/' . $userID . '/picture?type=large';
         $response = array('linkFoto' => $link);
     } else {
         $response = array('error' => 'error');
开发者ID:josekov1008,项目名称:Facebook-SimplePHP,代码行数:31,代码来源:server.php

示例4: FacebookRedirectLoginHelper

FacebookSession::setDefaultApplication($appid, $secret);
$helper = new FacebookRedirectLoginHelper($redirect_url);
try {
    $session = $helper->getSessionFromRedirect();
} catch (FacebookRequestException $ex) {
    // When Facebook returns an error
    echo $ex->getMessage();
} catch (\Exception $ex) {
    // When validation fails or other local issues
    echo $ex->getMessage();
}
if (isset($_SESSION['token'])) {
    // We have a token, is it valid?
    $session = new FacebookSession($_SESSION['token']);
    try {
        $session->Validate($appid, $secret);
    } catch (FacebookAuthorizationException $ex) {
        // Session is not valid any more, get a new one.
        $session = $helper->getSessionFromRedirect();
    }
}
?>

<?php 
require_once 'views/header.php';
?>

<?php 
if (isset($session) && $session) {
    // set the PHP Session 'token' to the current session token
    $_SESSION['token'] = $session->getToken();
开发者ID:andrei-popa,项目名称:XFactor_FBApp,代码行数:31,代码来源:index.php

示例5: unset

if (isset($_REQUEST['logout'])) {
    unset($_SESSION['fb_token']);
}
//2.Use app id,secret and redirect url
$app_id = 'APP_ID_HERE';
$app_secret = 'APP_SECRATE_HERE';
$redirect_url = 'REDIRECT_URL_HERE';
//3.Initialize application, create helper object and get fb sess
FacebookSession::setDefaultApplication($app_id, $app_secret);
$helper = new FacebookRedirectLoginHelper($redirect_url);
$sess = $helper->getSessionFromRedirect();
//check if facebook session exists
if (isset($_SESSION['fb_token'])) {
    $sess = new FacebookSession($_SESSION['fb_token']);
    try {
        $sess->Validate($id, $secret);
    } catch (FacebookAuthorizationException $e) {
        print_r($e);
    }
}
$loggedin = false;
//get email as well with user permission
$login_url = $helper->getLoginUrl(array('email'));
//logout
$logout = 'http://everythingissimple.com/apps/fblogin_bootstrap/index.php?logout=true';
//4. if fb sess exists echo name
if (isset($sess)) {
    //store the token in the php session
    $_SESSION['fb_token'] = $sess->getToken();
    //create request object,execute and capture response
    $request = new FacebookRequest($sess, 'GET', '/me');
开发者ID:Bachittarjeet,项目名称:My-Codes,代码行数:31,代码来源:index.php


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