-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