Facebook API退出我的应用程序,但不是Facebook

cdu*_*dub 6 javascript php facebook facebook-login

如何使用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));
Run Code Online (Sandbox Code Playgroud)

但是我点击我的网站上的注销,我将我的会话杀死到我的应用程序.然后,当你再次点击fb:login-button时,它只是打开和关闭,并没有做任何事情,因为我仍然连接到Facebook.我希望它重定向.

但是,如果我退出时我也使用Facebook :: logoutUrl,它会将我从我的应用程序和Facebook中导出,这不是我想要的.

Phi*_*asa 6

这对我有用:

window.fbAsyncInit = function() {

FB.getLoginStatus(function(response) {

    FB.api("/me/permissions", "delete", function(response){ 


    });

});

}
Run Code Online (Sandbox Code Playgroud)


Jam*_*ock 6

有点晚但可能会帮助别人.您可以撤消应用程序权限,从而有效地将其从应用程序中注销.这是代码:

FB.api('/me/permissions', 'delete', function(response) {
    console.log(response.status); // true for successful logout.
});
Run Code Online (Sandbox Code Playgroud)


Leo*_*uli 3

如果您使用 Facebook 登录,您确定只想注销您的应用程序,而不是 Facebook 吗?什么样的应用程序会想做这样的事情?为什么?这样做有什么好处呢?


但如果你真的想(破解),在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';
?>
Run Code Online (Sandbox Code Playgroud)

并在 logout.php 中:

$_SESSION['do_not_auto_login'] = true;
// destroy-code
Run Code Online (Sandbox Code Playgroud)

在 re_login.php 中:

unset($_SESSION['do_not_auto_login']);
header("location: /"); // re-direct back to index.php
Run Code Online (Sandbox Code Playgroud)

不完美,但效果还不错。希望你能成功!


但还是,为什么?如果您认为您的用户不想回来,请询问“如何从用户中删除我的 Facebook 应用程序?” 或者其他东西或者尝试@DMCS的答案..为什么?