Facebook logout button and redirect after logout

后端 未结 3 848
生来不讨喜
生来不讨喜 2021-02-08 15:43

I use this code



        
相关标签:
3条回答
  • 2021-02-08 16:06

    Above answer by Piskvor did it for me. Its crazy how many hours I've spend trying to figure this out.

    Main problem with plugins such as this Facebook for CakePHP is that they don't come with updates. APIs, especially popular ones like Facebook, change all the time because they are being imporved. If the guy who wrote it initially as a hobby moves on with his life and stops updating the SDK people who are less knowladgable on how to alter these things become stuck.

    WORKING CODE:

    Nevertheless, thanks for a great solution Piskvor, here is my piece of code for

    apps/plugins/facebook/views/helpers/facebook.php
    
                $init .= $this->Html->scriptBlock(
    <<<JS
    
    window.fbAsyncInit = function() {
        FB.init({
            appId : '{$appId}',
            session : {$session}, // don't refetch the session when PHP already has it
            status : true, // check login status
            cookie : true, // enable cookies to allow the server to access the session
            xfbml : true // parse XFBML
        });
         FB.Event.subscribe("auth.logout", function() {
           window.location = '/users/logout'
         });
        {$callback}
    };
    

    The key piece of code here is:

         FB.Event.subscribe("auth.logout", function() {
             window.location = '/users/logout'
         });
        {$callback}
    
    0 讨论(0)
  • 2021-02-08 16:11

    For integrated authentication (Facebook + Asp.Net MVC), I just use Javascript and FormsAuthentication.SignOut();

    function LogoutFacebook() {    
    FB.logout(function (response) {
        window.location = "/facebook/logout/";
    });   }
    
    0 讨论(0)
  • 2021-02-08 16:13

    Do the redirect yourself - add this to JavaScript, somewhere after FB.init():

    <script>
      FB.Event.subscribe("auth.logout", function() {window.location = '/logout'});
    </script>
    

    This function will fire when logout through the FB button happens.

    0 讨论(0)
提交回复
热议问题