我正在使用facebook API表单登录它正在工作,但问题是它显示页面刷新错误这里是我的代码请给我解决方案当我检索用户名nd id也可以当刷新(f5)页面时发生错误
<?php session_start();
require_once ('fb/autoload.php');
require_once ('fb/facebook.php');
$fb = new Facebook\Facebook([
'app_id' => '',
'app_secret' => '',
'default_graph_version' => 'v2.2',
]);
$helper = $fb->getRedirectLoginHelper();
$accessToken = $helper->getAccessToken(); //retrive accessToken
$permissions = ['email', 'public_profile', 'user_friends' ];
$loginUrl = $helper->
getLoginUrl('http://localhost/facebook/', $permissions);
if (isset($accessToken))
{
$_SESSION['facebook_access_token'] = (string) $accessToken;
}
if (isset($_SESSION['facebook_access_token']))
{
$oAuth2Client = $fb->getOAuth2Client();
$longLivedAccessToken =$oAuth2Client->
getLongLivedAccessToken($_SESSION['facebook_access_token']);
$_SESSION['fb_access_token'] = (string) $longLivedAccessToken;
$fb->setDefaultAccessToken($_SESSION['facebook_access_token']);
$response =$fb->
get('/me?locale=en_US&fields=name,email,gender,picture');
$userNode = $response->getGraphUser();
$id=$userNode->getId();
$name=$userNode->getName();
echo 'Logged in as ' . $name;
echo '<a href="out.php">out</a>'; //
}
else
{
echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';
}
?>