javascript - 检查页面加载时的 Facebook 登录状态

标签 javascript facebook

根据 Facebook Javascript SDK documentation ,

it is possible to check the user's status by setting status: true when you call FB.init.

To receive the response of this call, you must subscribe to the auth.statusChange event.

我相信我这样做是正确的,但我的示例中的“状态更改”日志从未触发:

window.fbAsyncInit = function() {
    FB.init({
        appId      : 'xxxxxxxxxxxx', // App ID
        channelUrl : '../channel.html', // Channel File
        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.statusChange', function(response) {
        console.log("status change!");
    });
    ...
});

此文档是否不正确?还是我做错了什么?

最佳答案

我认为最后而不是});是 };

也可能是您没有启动。这对我有用:

$(document).ready(function() {

  var app_id = 'xxxxxxxxxxxxxx';

  var start = function (){


    window.fbAsyncInit = function() {

     FB.init({

        appId     : app_id,
        status    : true,
        cookie    : true,
        xfbml     : true,
        version   : 'v2.7'

     });

     FB.Event.subscribe('auth.statusChange', function(response) {
        var status = response.status;
        console.log(response.status);

        if (status === "connected") {
         //
        }

     });
   };

  }

  start();

 });

关于javascript - 检查页面加载时的 Facebook 登录状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15721806/

相关文章:

android - React-Native 通过教程 Facebook 获取 JSON 返回错误

facebook - 如何在我网站的评论中显示 facebook 和 twitter 用户个人资料图片

Android Studio 1.1.0 Facebook SDK 登录

javascript - jQuery 固定内容如果大于 View 则滚动

javascript - 在 JSConfig.json 文件中看到未知的 typescript 错误

javascript - 如何使用 JavaScript 获取本地/内部 IP

javascript - Firebase Web 获取 Google 和 Facebook 中的提供商数据(性别和生日)

javascript - 无法在 Atom 编辑器中使用 eslint

javascript - 用 div 覆盖全屏 - RWD overflow's

IOS Facebook 通过应用程序登录