本文整理汇总了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;
}
示例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;
}
示例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');
示例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();
示例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');