<?php
session_start();
//included file and use
$app_id = 'xxx';
$app_secret = 'xxx';
FacebookSession::setDefaultApplication($app_id, $app_secret);
$helper = new FacebookRedirectLoginHelper("`http://example/facebook4.0`/", $app_id, $app_secret);
try
{
$session = $helper->getSessionFromRedirect();
}
catch(FacebookRequestException $ex) { }
catch(Exception $ex) { }
$loggedIn = false;
if (isset($session))
{
if ($session)
{
$loggedIn = true;
try { //logged here and get data
$user_profile = (new FacebookRequest(
$session, 'GET', '/me'
))->execute()->getGraphObject(GraphUser::className());
print_r($user_profile); //print data
}
catch(FacebookRequestException $e) {
echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage();
}
}
}
if(!$loggedIn) //if user is not online // get link and add scope
{
$loginUrl = $helper->getLoginUrl(array('public_profile','email'));
echo "<a href='$loginUrl'>Login With Facebook</a>";
}
else
{
print_r($user_profile); //logout link is generated here
echo '<br><br><a href="index.php">Logout</a>'; //print to sceen
// i dont have more comment to write stack over flow please update it without eating my head to write comments here
}
?>
从上周开始工作,但今天根本没有工作,重定向后什么都没显示
答案 0 :(得分:-2)
可能是您的appID和app Secret已更改。试着确认一下。