我有这个 facebook 应用程序可以在我的网站上显示 fb 通知。然后我遇到了这个问题,假设有两个用户 Alice 和 Bob。Alice 是我网站的常客,她向 Bob 推荐了它。她让他从她自己的笔记本电脑上注册到我的网站。当 bob 尝试添加应用程序时,Alice 的 fb 通知出现了。实际上,当 Bob 单击登录链接时,由于 alice 已经登录到 facebook,它只是提取了她的详细信息(同一会话),如何解决这种情况,我们是否必须让 Alice 从 facebook 注销并让 Bob 登录,类似于“Alice 已经登录,以其他用户身份登录”,有人可以提出一些解决方案以及如何做到这一点。
以下是我用于登录的一段代码
require_once('sdk/src/facebook.php');
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'cookie' => true
));
// Get User ID
$user = $facebook->getUser();
// Login or logout url will be needed depending on current user state.
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
//check permissions list
if ($user) {
$permissions_list = $facebook->api('/me/permissions','GET', array('access_token' => $access_token));
//check if the permissions we need have been allowed by the user
//if not then redirect them again to facebook's permissions page
//
$permissions_needed = array('manage_notifications','publish_stream', 'read_stream');
$login_url_params = array(
'scope' => 'manage_notifications,publish_stream,read_stream',
'fbconnect' => 1,
'display' => "page",
'next' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']
);
foreach($permissions_needed as $perm) {
if( !isset($permissions_list['data'][0][$perm]) || $permissions_list['data'][0][$perm] != 1 ) {
$login_url_params = array(
'scope' => 'manage_notifications,publish_stream,read_stream',
'fbconnect' => 1,
'display' => "page",
'next' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']
);
$login_url = $facebook->getLoginUrl($login_url_params);
echo $login_url;
header("Location: {$login_url}");
exit();
}
}
//if the user has allowed all the permissions we need,
//get the information about the pages that he or she managers
$accounts = $facebook->api(
'/me',
'GET',
array(
'access_token' => $access_token
)
);
}
else {
//if not, let's redirect to the ALLOW page so we can get access
//Create a login URL using the Facebook library's getLoginUrl() method
$login_url_params = array(
'scope' => 'manage_notifications,publish_stream,read_stream',
'fbconnect' => 1,
'display' => "page",
'next' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']
);
$login_url = $facebook->getLoginUrl($login_url_params);
//redirect to the login URL on facebook
$facebook_login = $login_url;
echo "<a href='$login_url'>Login Facebook</a>";