如果用户登录到 Facebook,我的 MVC 应用程序首先被检测到:\
function isLoggedIn(callback, param1) {
window.FB.getLoginStatus(function (response) {
if (response.status === 'connected') {
updateUser(response.authResponse);
callback(param1);
} else {
login(callback, param1);
}
});
}
如果用户未连接,我使用此功能登录:
function login(callback, success) {
window.FB.login(function (response) {
if (response.authResponse) {
updateUser(response.authResponse, callback, success);
callback(success);
} else {
callback(null);
}
});
}
此外,我还订阅了更改状态:
FB.Event.subscribe('auth.authResponseChange', function (response) {
if (response.status === 'connected') {
top.location.href = top.location.href;
//window.location.reload();
}
if (response.status != 'connected' && response.status != 'not_authorized') {
updateUser(null);
}
});
我必须在用户登录后刷新页面才能在服务器上获取 FacebookSignedRequest。
top.location.href = top.location.href 和 window.location.reload() 不起作用...任何建议:)