我一直在尝试使用 Facebooker2 作为在 Rails 中通过 Facebook 登录的一种方式。但是,Facebooker2 的 current_facebook_user 函数以某种方式返回 nil,即使我肯定已登录 Facebook。有任何想法吗?谢谢!
这是我的代码的要点:
在我的一个控制器中:
def check_login
if current_facebook_user.nil?
"This always gets returned, even though I'm logged into Facebook."
else
"This never gets run"
end
end
脸书 JS。中的行FB.Event.subscribe('auth.login', function(response) { ... }重定向到check_login上面的函数。
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '123456789012345',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
channelUrl : 'true', // add channelURL to avoid IE redirect problems
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.login', function(response) {
window.location = "http://www.mysite.com/check_login";
});
}; ( function() {
var s = document.createElement('div');
s.setAttribute('id', 'fb-root');
document.documentElement.getElementsByTagName("body")[0].appendChild(s);
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
s.appendChild(e);
}());
function logout() {
FB.logout();
window.location = 'http://www.mysite.com/logout';
};
</script>