简体   繁体   English

Facebook getLogoutUrl()无法按预期工作

[英]Facebook getLogoutUrl() doesn't work as expected

This is my code : 这是我的代码:

    <?php
require_once("facebook-php-sdk/src/facebook.php");
    define('YOUR_APP_ID', 'xxxxxxxxxxxxx');
    define('YOUR_APP_SECRET', 'xxxxxxxxxxxxxxxxxxxxxxxx');
    $facebook = new Facebook(array(
     'appId' => YOUR_APP_ID,
     'secret' => YOUR_APP_SECRET,
    ));
    $userId = $facebook->getUser();
    if($userId){
         $userInfo = $facebook->api('/' + $userId);
         $fbid = $userInfo['id'];
         $params = array();
         echo '<a href='.$facebook->getLogoutUrl($params).'><div class="text-facebook"><img style="vertical-align:middle;" src="/img/fbicon.png">Logout</div></a>';                         
               }
                else{
                  $permission = array('scope' => 'email');
                  echo '<a href='.$facebook->getLoginUrl($permission).'><div class="text-facebook"><img style="vertical-align:middle;" src="/img/fbicon.png">Login with Facebook</div></a>';
                     }
?>

Login works perfectly, but when I click the Logout button it logs me out of facebook.com, but it stays logged on my website, which is exactly the opposite of what I want. 登录工作完美,但当我点击退出按钮时,它会将我从facebook.com中导出,但它会保留在我的网站上,这与我想要的完全相反。 I want the link to delete all facebook information from my website, but keep the user logged to facebook. 我想要链接从我的网站删除所有Facebook信息,但让用户登录到Facebook。

I don't know if I explained correctly what I need, but I'll clear things up if someone asks. 我不知道我是否正确解释了我需要什么,但如果有人问我,我会清楚的。

If you want the user to log out from your site but stay logged in to facebook then the answer is simple: 如果您希望用户从您的网站注销但仍然登录到Facebook,那么答案很简单:

Don't use facebook->getlogouturl() 不要使用facebook-> getlogouturl()

If after a successful login, you set a variable to be true, and use that to permit actions you only grant to a logged in user, then all your logout button will need to do is set that variable to false. 如果成功登录后,您将变量设置为true,并使用该变量允许您仅授予登录用户的操作,那么您需要执行的所有注销按钮都将该变量设置为false。

The issue here isn't the logout link (which is working properly, since it logs you out of Facebook), but it is how your website checks whether you are still logged into Facebook 这里的问题不是退出链接(它正常工作,因为它会让你退出Facebook),但它是你的网站检查你是否仍然登录Facebook的方式

The Facebook API you are using only deals with Facebook's side of things. 您使用的Facebook API仅处理Facebook的一面。 The login link will log you into Facebook, and the logout link will log you out of Facebook. 登录链接将登录到Facebook,登出链接将使您退出Facebook。 It doesn't affect your website directly. 它不会直接影响您的网站。

You'll need to find out how your website decides whether you are still logged into Facebook or not, and go from there. 您需要了解您的网站如何决定您是否仍然登录Facebook,并从那里开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM