Solved

FB.logout() called without an access token.

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
facebook api login permission scope : user_likes 1 2,121
How to get financial reports for my app from Facebook 4 297
WhatApps and Facebook 1 973
Using Google for Facebook Results 11 122
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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

803 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