检测脸书用户是否在没有弹出窗口的情况下登录

Detect if facebook user is logged in with no popups

本文关键字:窗口 登录 情况下 用户 是否 检测      更新时间:2023-09-26

我正在尝试检查用户是否已在Facebook中登录(并重定向到其他页面(,但我无法为此打开任何弹出窗口:

这将起作用:但如果用户未登录Facebook,则会打开一个弹出窗口

FB.login(function(response) {
    if(response.status == 'connected')
              /*Redirect here*/
});

这在我的另一个网络中工作,但不在这里

window.fbAsyncInit = function() {
                FB.init({
                  appId      : myAppid, // App ID 
                  status     : true, // check login status
                  cookie     : true, // enable cookies to allow the server to access the session
                  xfbml      : true  // parse XFBML
                });
                FB.Event.subscribe('auth.login', function() {
                      /* REDIRECT HERE */
                });
              };
              // Load the SDK Asynchronously
              (function(d){
                 var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
                 if (d.getElementById(id)) {return;}
                 js = d.createElement('script'); js.id = id; js.async = true;
                 js.src = "//connect.facebook.net/es_ES/all.js";
                 ref.parentNode.insertBefore(js, ref);
               }(document));

这里有什么线索吗?

您可以使用

FB.getLoginStatus来获取所需的信息。

在当前浏览器会话中第一次调用 FB.getLoginStatus,或者使用 status: true 初始化 JS SDK,响应对象将由 SDK 缓存。对 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.
  }
});