javascript Facebook API 注销我的应用程序但不是 facebook

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9189386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 05:52:33  来源:igfitidea点击:

Facebook API Logout of my app but not facebook

phpjavascriptfacebookfacebook-login

提问by cdub

How do I make a logout using Facebook's api log me out of my app (a website), but keep me logged into facebook.com?

如何使用 Facebook 的 api 注销我的应用程序(一个网站),但让我登录到 facebook.com?

This logs me in alright:

这让我登录好了:

 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));

But then I click logout on my site which I kill my session to my app. Then when you click on the fb:login-button again, it just opens and closes and doesn't do anything because I'm still connected to facebook. I want it to redirect.

但是然后我在我的网站上单击注销,我终止了与我的应用程序的会话。然后,当您再次单击 fb:login-button 时,它只是打开和关闭并且不执行任何操作,因为我仍然连接到 facebook。我希望它重定向。

But if when I logout I also use Facebook::logoutUrl it logs me out of my app AND facebook which is not what I want.

但是,如果当我注销时我也使用 Facebook::logoutUrl,它会将我从我的应用程序和 Facebook 中注销,这不是我想要的。

采纳答案by Leonard Pauli

Are you sure you want to only logout of your app, and not fb too, if you logged in using fb? What kind of app could want to do something like that? And why? What's the benefit of doing so?

如果您使用 fb 登录,您确定只想退出您的应用程序而不是 fb 吗?什么样的应用程序可能想做这样的事情?为什么?这样做有什么好处?



But if you really want to (hack), in index.php:

但是如果你真的想(hack),在 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';
?>

and in logout.php:

并在 logout.php 中:

$_SESSION['do_not_auto_login'] = true;
// destroy-code

and in re_login.php:

在 re_login.php 中:

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

Not perfect, but works somewhat good. Hope you get the hack!

不完美,但效果有点好。希望你能破解!



But still, why?? If you don't think your user would like to come back, ask "How to remove my fb-app from user?" or something instead or try @DMCS's answer.. Why?

但是,为什么?如果您认为您的用户不想回来,请询问“如何从用户中删除我的 fb-app?” 或者别的什么,或者尝试@DMCS的答案..为什么?

回答by Phil LaNasa

This works for me:

这对我有用:

window.fbAsyncInit = function() {

FB.getLoginStatus(function(response) {

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


    });

});

}

回答by James Lock

A bit late but might help someone. You can revoke app permissions which effectively logs them out of your app. Here's the code:

有点晚了,但可能会帮助某人。您可以撤销应用权限,从而有效地将它们从您的应用中注销。这是代码:

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

回答by Leon

You need to use destroySessionfor Facebook to do

你需要使用destroySessionFacebook 来做

www.example.com?act=logout

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);

?>

Maybe you need to set param to make it redirect.

也许您需要设置 param 以使其重定向。

回答by DMCS

When the user is logged into your app, send an HTTP DELETE call to /me/permissionsusing their current access token. This will log them out of your app requiring them to re-authenticate if they want to play some more. Also be sure to destroy the php session using normal php session clearing code.

当用户登录到您的应用程序时,发送 HTTP DELETE 调用以/me/permissions使用他们当前的访问令牌。这会将他们从您的应用程序中注销,如果他们想玩更多游戏,则要求他们重新进行身份验证。还要确保使用正常的 php 会话清除代码销毁 php 会话。