Facebook API Exit from my application but not facebook

How to log out using Facebook api from my application (website), but don’t make me log in to facebook.com?

This puts me in order:

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 log out on my site, and I kill my session in my application. Then, when you press the fb: login button again, it just opens and closes and does nothing, because I'm still connected to facebook. I want it redirected.

But if I also use Facebook :: logoutUrl when logging out, it takes me out of my AND facebook application, which is not what I want.

+6
source share
5 answers

Do you really only want to exit your application, not fb, if you are logged in with fb? Which application might want to do something like this? And why? What is the use of this?


But if you really want to (hack), in 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:

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

and in re_login.php:

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

Not perfect, but works somewhat well. Hope you get a hack!


But still, why? If you do not think that your user would like to return, ask: "How to remove my fb application from the user?" or something instead or try @DMCS answer .. Why?

+3
source

This works for me:

 window.fbAsyncInit = function() { FB.getLoginStatus(function(response) { FB.api("/me/permissions", "delete", function(response){ }); }); } 
+6
source

A little late, but can help someone. You can revoke the permissions of applications that effectively register them from your application. Here is the code:

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

You need to use destroySession for Facebook

www.example.com?act=logout

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

You may need to set the parameter so that it is redirected.

+1
source

When a user logs into your application, send an HTTP DELETE call to /me/permissions using your current access token. This will get them out of your application, requiring re-authentication if they want to play some more. Also remember to destroy the php session using the regular php session cleanup code.

0
source

Source: https://habr.com/ru/post/907911/


All Articles