我使用 FB JDK 在我的网站上启用了 FB 登录。当我使用它时,它完美地工作:对话窗口打开,我授权,authResponse
是预期的。当另一个用户使用它时(尚未授权该应用程序,但已登录到 FB),登录对话框会出现一秒钟,然后立即消失,响应对象的状态为 not_authorized
。关于为什么对话框可能不要求用户授权的任何想法?
在我的布局中(Haml):
%body
#fb-root
:javascript
window.fbAsyncInit = function() {
FB._https = false;
FB.init({
appId : <App ID>
status : true,
cookie : true,
oauth : true,
xfbml : true
});
FB.getLoginStatus(function(response) {
if(window.reportFBstatus) {
reportFBstatus(response);
}
}, true);
};
// Load the SDK
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
登录链接:
%a{href: '#', onclick: 'FB.login(window.reportFBstatus, {scope: "user_about_me"})'}
在 Coffeescript 中:
window.reportFBstatus = (response) ->
$.ajaxSetup({
headers:
'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
})
console.log response # always shows status=not_authorized for other users
if response.status is 'connected'
auth = response.authResponse
$.post('/login', {fb_id: auth.userID, fb_token: auth.accessToken}, (data) ->
window.currentUser = data
)
最佳答案
对我有用的解决方案实际上是一个愚蠢的解决方案——我忘记在 developers app console on Facebook 中将应用程序从沙盒模式更改为实时模式。 (单击左侧的应用程序)。或者,我可以添加我希望能够以开发人员或测试人员身份登录的人员。
希望对其他人有所帮助!
关于ruby-on-rails - fb.Login() 窗口立即关闭并返回 'not_authorized',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17003764/