检测facebook用户是否在没有弹出窗口的情况下登录 [英] Detect if facebook user is logged in with no popups

查看:98
本文介绍了检测facebook用户是否在没有弹出窗口的情况下登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to check if the user is logged in in facebook (and redirect to other page) but I can't open any popup for this:

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

This will work: but would open a popup in case the user is NOT logged in facebook

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

这是在我的另一个网站上工作的,但不是在这里

This is working in another web of mine, but not 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 以获得所需的信息.

You can use FB.getLoginStatus to get the info you want.

在当前浏览器会话中第一次调用FB.getLoginStatus或使用status: true初始化JS SDK时,响应对象将被SDK缓存.随后调用FB.getLoginStatus将从此缓存的响应中返回数据.

The first time in the current browser session that FB.getLoginStatus is called, or the JS SDK is init'd with status: true, the response object will be cached by the SDK. Subsequent calls to FB.getLoginStatus will return data from this cached response.

文档示例:

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

这篇关于检测facebook用户是否在没有弹出窗口的情况下登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆