How to detect user logging out of Facebook after logging into my app?

前端 未结 2 738
逝去的感伤
逝去的感伤 2021-01-20 06:24

My application uses Facebook authentication:

FB.init({

    appId: config.fbAppId,
    status: true,
    cookie: true,
//  xfbml: true,
//  channelURL : \'ht         


        
2条回答
  •  孤城傲影
    2021-01-20 06:51

    What you could try and use is the FB.getLoginStatus where if the user is connected this would allow them to complete the wall post. If they aren't connected then call the FB.login method before they can post on the wall.

    FB.getLoginStatus(function(response) {
        if (response.status === 'connected') {
            // the user is logged in and has authenticated your
            // app, and response.authResponse supplies
            // the user's ID, a valid access token, a signed
            // request, and the time the access token 
            // and signed request each expire
            var uid = response.authResponse.userID;
            var accessToken = response.authResponse.accessToken;
        } else if (response.status === 'not_authorized') {
            // the user is logged in to Facebook, 
            // but has not authenticated your app
        } else {
            // the user isn't logged in to Facebook.
        }
    });
    

    http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

    There are also the events for login and logout that you can watch for and do something with those responses.

    FB.Event.subscribe('auth.login', function(response) {
        // do something with response
    });
    
    FB.Event.subscribe('auth.logout', function(response) {
        // do something with response
    });
    

    http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

提交回复
热议问题