gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 09:15:27 25 4
gpt4 key购买 nike

根据 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com