fb.Login()窗口立即关闭并返回'not_authorized'

Raf*_*afi 7 facebook ruby-on-rails facebook-javascript-sdk

我在我的网站上使用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));
Run Code Online (Sandbox Code Playgroud)

登录链接:

%a{href: '#', onclick: 'FB.login(window.reportFBstatus, {scope: "user_about_me"})'}
Run Code Online (Sandbox Code Playgroud)

在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
    )
Run Code Online (Sandbox Code Playgroud)

Raf*_*afi 15

对我有用的解决方案实际上是一个愚蠢的解决方案 - 我忘记在Facebook上的开发者应用控制台中将应用程序从沙盒模式更改为实时模式(单击左侧的应用程序).或者,我可以添加我想要作为开发人员或测试人员登录的人员.

希望能帮到别人!