Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook JS API can't logout

I have a localhost website and script with FB.logout(). After some actions, it fails to log me out and I see next error message in console:

Refused to display 'https://www.facebook.com/home.php' in a frame because it set 'X-Frame-  Options' to 'DENY'. 

I searched all StackOverflow and didn't find any working solution. Network inspector shows cancelled near home.php query.
So I understand that the script tries to load the Facebook homepage in a frame, but it can't because it is prohibited. So how can I fix it? Why doesn't logout() work for me?

My code

// Facebook Basic Example  window.fbAsyncInit = function() {   FB.init({     appId      : '579651098766258',     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.authResponseChange', function(response) {     if (response.status === 'connected') {       testAPI();     } else if (response.status === 'not_authorized') {       FB.login();     } else {       FB.login();     }   }); };  (function(d){  var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];  if (d.getElementById(id)) {return;}  js = d.createElement('script'); js.id = id; js.async = true;  js.src = "//connect.facebook.net/en_US/all.js";  ref.parentNode.insertBefore(js, ref); }(document));    function testAPI() {   FB.api('/me', function(res) {     console.log(res);     setTimeout(function(){       FB.logout(); // <-- ERROR     }, 2000);   }); } 
like image 719
Enthusiast Avatar asked Mar 11 '14 16:03

Enthusiast


1 Answers

This solution worked for me:

  1. Go to Settings tab in your facebook application and in Basic tab scrolldown to +Add Platform
  2. Click on +Add Platform and choose Website
  3. Add your url of your website (for me, was the same url added on Advanced tab on Redirect URIs)
  4. Save changes and test again.

Also I made a youtube video to solve this problem: https://www.youtube.com/watch?v=7CNpLgwa0-c

enter image description here

like image 75
SoldierCorp Avatar answered Sep 17 '22 20:09

SoldierCorp