2011-12-20 319 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. 
    } 
});