我在我的网站上使用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中将应用程序从沙盒模式更改为实时模式(单击左侧的应用程序).或者,我可以添加我想要作为开发人员或测试人员登录的人员.
希望能帮到别人!