2011-12-20 320 views
0

我有一个网站,用户可以使用Facebook登录。用户可以注册他们的Facebook帐户,这很好。Facebook登录身份验证

问题是如果他们回到我的网站,但他们已经登录到Facebook。 我如何将它们自动登录到我的网站?

我正在使用Razor的Facebook帮手。

回答

0

我假设您使用Facebook的JavaScript SDK?

在这种情况下,您可以使用FB.getLoginStatus()方法来确定它们是否已登录到Facebook。

有问题的代码如下所示:

FB.getLoginStatus(function (res) { 
    if (res.authResponse) { 
    //User is authenticated with FB and your app 
    //You can now load the Facebook User through FB.get('/me') 
    } else 
    { 
    FB.login(function() { 
     //Callback once the user logged into FB and gave your app permission 
     //Same as above 
    }); 
    } 
}); 
+0

对我来说太快了;) – Lix 2011-12-20 14:59:23

0

来自Facebook的采取的JavaScript SDK文档 - FB.getLoginStatus()

要确定用户是否连接到您的应用程序:

FB.getLoginStatus(function(response) { 
    if (response.status === 'connected') { 
    // the user is logged in and connected to 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 not connected to the app 
    } else { 
    // the user isn't even logged in to Facebook. 
    } 
});