-1
因此,作为标题摘要我使用Facebook的PHP SDK授权用户在我的网站上,我遇到的问题是,几分钟后beeing登录,我刷新页面$ user = $ facebook->的getUser();已经消失,页面认为我已注销,但如果我再次刷新,它又被授权。Facebook serverside登录问题
的index.php
<?php
session_start();
include_once "facebook/fbaccess.php";
?>
fbaccess.php
<?php
//Application Configurations
$app_id = "xxxxxxxxxxxxx";
$app_secret = "XXXXXXXXXXXXXXXXXXXXX";
$site_url = "http://xxxxxxxxx";
try{
include_once "facebook.php";
}catch(Exception $e){
error_log($e);
}
// Create our application instance
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
// Get User ID
$user = $facebook->getUser();
// We may or may not have this data based
// on whether the user is logged in.
// If we have a $user id here, it means we know
// the user is logged into
// Facebook, but we don’t know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
$facebook->setExtendedAccessToken();
$access_token = $facebook->getAccessToken();
if($user){
//==================== Single query method ======================================
try{
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
$_SESSION['fid'] = $user_profile['id'];
}catch(FacebookApiException $e){
error_log($e);
$user = NULL;
}
//==================== Single query method ends =================================
}
if($user){
// Get logout URL
$logoutUrl = $facebook->getLogoutUrl();
}else{
// Get login URL
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'publish_stream', 'offline_access',
'redirect_uri' => $site_url,
));
}
?>
的index.php
<div id="mainMenu">
<?php if ($user) {echo '<a href="' . $logoutUrl . '"><h5>Logout</h5></a>'; }else{ echo '<a href="' . $loginUrl . '"><h5>Login</h5></a>';} ?>
</div>
你不假设显示应用程序正确率 –
我认为问题将从您的会话结束,而不是从FACEBOOK。尝试增加您的服务器在您运行此应用程序的会话时间 – Vijay
不认为它是会话,但我不确定它是什么。正如我之前所说,我只是需要刷新它的工作,所以我猜测第二次刷新,它认识到我在Facebook上进入并重新授权。 – user1593846