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