如何确定用户是否通过facebook javascript sdk确认或取消了登录

时间:2013-07-01 19:06:43

标签: facebook web login facebook-javascript-sdk

我通过facebook的Javascript SDK将用户登录到网站。在用户点击“通过fb登录”按钮后,我想根据用户在facebook的确认中点击“确定”或“取消”来生成不同的响应。这是我单击fb按钮时使用的代码。

$("#fb").click(function() {
    FB.login(function(response){
        FB.api('/me',function(response){

            // I believe the test to see if they are logged in or not should go here

        });//FB.api
    },{scope:'publish_actions, email, user_likes, user_location'});
});

任何建议表示赞赏。谢谢!

1 个答案:

答案 0 :(得分:0)

根据facebook的documentation

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
    alert('a');
  } else if (response.status === 'not_authorized') {
    // the user is logged in to Facebook, 
    // but has not authenticated your app
    alert('b');
  } else {
    // the user isn't logged in to Facebook.
    alert('c');
  }
 });

它对我有用。希望它可以帮助别人。