Solved

FB.logout() called without an access token.

Posted on 2013-11-26
1
3,346 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
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
This article will take you step-by-step through the basics of ad creation on facebook. You will learn how to create ads for mobile newsfeed, desktop newsfeed, and right column. 1. Login to your Facebook account. In the left column, click on “Crea…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now