如果用户已经授权离线访问,则自动登录

时间:2012-02-21 18:54:39

标签: facebook facebook-c#-sdk facebook-javascript-sdk

我让一切正常,包括使用Javascript SDK登录。当用户第一次访问我的应用程序时,他们将单击登录以获取初始令牌并授权offline_access。

我需要的是,当该用户返回时,它(在控制器中)会自动将它们登录到FB,以便我可以再次访问他们的帐户,而无需单击“登录到FB”按钮。

谢谢!

1 个答案:

答案 0 :(得分:2)

您需要使用Facebook Javascript SDK执行此操作。在页面加载时调用方法'getLoginStatus',您可以确定用户是否已授权您的应用程序。请参阅:https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

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.
  }
 });