Solved

FB.logout() called without an access token.

Posted on 2013-11-26
1
3,613 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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
donation page 6 130
Can I make a 3 Gig video into 25MB 13 79
how does facebook / twitter store data? 3 142
Facebook – Page type 12 104
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
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…

820 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