javascript - 检测 facebook 用户是否在没有弹出窗口的情况下登录

标签 javascript jquery facebook

我正在尝试检查用户是否已登录 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获取您想要的信息。

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

关于javascript - 检测 facebook 用户是否在没有弹出窗口的情况下登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10698475/

相关文章:

jquery - 在没有提交按钮的情况下使用 Enter 键提交表单?

javascript - 如何在 jquery 中使用下拉列表在 <td> 中插入 textarea 内容

ios - 来自 ios 应用程序的 facebook 请求未显示在 facebook 移动应用程序中

javascript - jQuery 在内联 onclick 中传递对象

javascript - 为什么当 parseFloat 用于小数点后 15 位时,JS 会降低数字?

javascript - 将 JavaScript 值以明文形式保存在数据库中

node.js - 检查 botframework (node.js) 的 facebook 点赞情况

javascript - 从js到div的多个数据

javascript - if else 内循环

javascript - 将带有图像和文本的链接发布到 Facebook 墙