如何使用Facebook的api注销我的应用程序(一个网站),但让我登录Facebook.com?
这让我登录好了:
window.fbAsyncInit = function()
{
FB.init({
appId : '<?= APP_ID ?>',
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
FB.Event.subscribe('auth.login', function(response)
{alert(response);
window.location = 'http://reviewsie.com/accounts/facebook';
});
};
(function(d)
{
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
但后来我在我的网站上点击注销,我终止了我的应用程序会话。然后,当你再次点击fb:login按钮时,它只是打开和关闭,什么都不做,因为我仍然连接到facebook。我希望它重定向。
但如果我注销时也使用Facebook::logoutUrl,它会将我从应用程序和Facebook中注销,这不是我想要的。
有点晚了,但可能会帮助到别人。您可以吊销应用程序权限,从而有效地将其从应用程序中注销。这是代码:
FB.api('/me/permissions', 'delete', function(response) {
console.log(response.status); // true for successful logout.
});
这对我有效:
window.fbAsyncInit = function() {
FB.getLoginStatus(function(response) {
FB.api("/me/permissions", "delete", function(response){
});
});
}
如果使用fb登录,您确定只想注销应用程序,而不想注销fb吗?什么样的应用程序可以做这样的事情?为什么?这样做有什么好处?
但如果你真的想(破解),在index.php:
<?php
require 'init.php'; // general init
require 'init_fb.php'; // sets $fb_id if logged in to fb
if (isset($fb_id) and !isset($_SESSION['do_not_auto_login'])) {
echo "<a href='/logout'>Logout</button>";
include 'app.php';
return;
}
if (isset($_SESSION['do_not_auto_login'])
echo "<a href='/re_login'>FB Login</button>";
else include 'html_and_js_fb_login_code_and_button.php';
include 'startpage.php';
?>
和在注销中。hp:
$_SESSION['do_not_auto_login'] = true;
// destroy-code
以及在re_login.hp:中
unset($_SESSION['do_not_auto_login']);
header("location: /"); // re-direct back to index.php
不完美,但效果不错。希望你得到破解!
但是,为什么??如果你认为你的用户不想回来,可以问"如何从用户中删除我的fb应用程序?"或其他问题,或者试试@DMCS的答案。。为什么?
您需要为Facebook使用destroySession
来进行
www.example.com?act=退出
<?php
php sdk blah blah
if($_GET['act'] =='logout'){
$facebook->destroySession();
}
$params = array(
'scope' => 'read_stream, friends_likes',
'redirect_uri' => 'https://www.myapp.com/post_login_page'
);
$loginUrl = $facebook->getLoginUrl($params);
?>
也许您需要设置param以使其重定向。
当用户登录到您的应用程序时,使用其当前访问令牌向/me/permissions
发送HTTP DELETE调用。这将使他们从您的应用程序中注销,如果他们想玩更多游戏,则需要重新进行身份验证。还要确保使用正常的php会话清除代码销毁php会话。