[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

FB.logout() called without an access token.

Posted on 2013-11-26
1
Medium Priority
?
4,113 Views
Last Modified: 2013-11-27
When I call FB.logout(function(response) {
                  window.location = '/guests/home';
            });

I always get the error message FB.logout() called without an access token.

I can't figure out how to make it work.

<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
        FB.init({
            appId      : '3102287691*****',
            status     : false,
            cookie     : true,
            xfbml      : true
        });
        
		  // Here we subscribe to the auth.authResponseChange JavaScript event. This event is fired
		  // for any authentication related change, such as login, logout or session refresh. This means that
		  // whenever someone who was previously logged out tries to log in again, the correct case below 
		  // will be handled. 
		  FB.Event.subscribe('auth.authResponseChange', function(response) {
		    // Here we specify what we do with the response anytime this event occurs. 
		    var accessToken = response.authResponse.accessToken;
		    if (response.status === 'connected') {
		      // The response object is returned with a status field that lets the app know the current
		      // login status of the person. In this case, we're handling the situation where they 
		      // have logged in to the app.
				 FB.api('/me', function(response) {
			      fbLogMe(response.email,accessToken);
		            // Here, I can display the welcome message :)
		            });      

		    } else if (response.status === 'not_authorized') {
		      // In this case, the person is logged into Facebook, but not into the app, so we call
		      // FB.login() to prompt them to do so. 
		      // In real-life usage, you wouldn't want to immediately prompt someone to login 
		      // like this, for two reasons:
		      // (1) JavaScript created popup windows are blocked by most browsers unless they 
		      // result from direct interaction from people using the app (such as a mouse click)
		      // (2) it is a bad experience to be continually prompted to login upon page load.
		      FB.login(function(response) {},{scope: 'email'});
		    } else {
		      // In this case, the person is not logged into Facebook, so we call the login() 
		      // function to prompt them to do so. Note that at this stage there is no indication
		      // of whether they are logged into the app. If they aren't then they'll see the Login
		      // dialog right after they log in to Facebook. 
		      // The same caveats as above apply to the FB.login() call here.
				FB.login(function(response) {},{scope: 'email'});
		    }
		  });   


	function fbLogout(accessToken){

		FB.logout(function(response) {
		  // user is now logged out
			window.location = getRootPath() + 'guests/home';
		});		
	}
 </script> 

Open in new window

0
Comment
Question by:ymorin007
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 1500 total points
ID: 39680747
Try this :
<script>
	window.fbAsyncInit = function() {
		FB.init({
			appId      : '3102287691*****',
			status     : false,
			cookie     : true,
			xfbml      : true
		});

		// Here we subscribe to the auth.authResponseChange JavaScript event. This event is fired
		// for any authentication related change, such as login, logout or session refresh. This means that
		// whenever someone who was previously logged out tries to log in again, the correct case below 
		// will be handled. 
		FB.Event.subscribe('auth.authResponseChange', function(response) {
			// Here we specify what we do with the response anytime this event occurs. 
			var accessToken = response.authResponse.accessToken;
			if (response.status === 'connected') {
				// The response object is returned with a status field that lets the app know the current
				// login status of the person. In this case, we're handling the situation where they 
				// have logged in to the app.
				FB.api('/me', function(response) {
					fbLogMe(response.email,accessToken);
					// Here, I can display the welcome message :)
				});      
		
			} else if (response.status === 'not_authorized') {
				// In this case, the person is logged into Facebook, but not into the app, so we call
				// FB.login() to prompt them to do so. 
				// In real-life usage, you wouldn't want to immediately prompt someone to login 
				// like this, for two reasons:
				// (1) JavaScript created popup windows are blocked by most browsers unless they 
				// result from direct interaction from people using the app (such as a mouse click)
				// (2) it is a bad experience to be continually prompted to login upon page load.
				FB.login(function(response) {},{scope: 'email'});
			} else {
				// In this case, the person is not logged into Facebook, so we call the login() 
				// function to prompt them to do so. Note that at this stage there is no indication
				// of whether they are logged into the app. If they aren't then they'll see the Login
				// dialog right after they log in to Facebook. 
				// The same caveats as above apply to the FB.login() call here.
				FB.login(function(response) {},{scope: 'email'});
			}
		});   

		FB.getLoginStatus(fbLogout);

		function fbLogout(response){
		
			if(!response.session) {
				// user is now logged out
				window.location = getRootPath() + 'guests/home';
				return;
			}

			FB.logout(fbLogout);		
		}
	}
</script> 

Open in new window

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, you will learn how to create custom audiences using your own email lists. You can use this custom audience as your target audience for advertising on Facebook. This allows you to advertise to your existing audience. Once you've crea…
Owning a franchise can be the dream of a lifetime. It provides a chance for economic growth. You can be as successful as you want.  To make your franchise successful, you need to market it successfully. Here are six of the best marketing strategies …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question