0
New to Facebook apps, developing a test app using JavaScript:
  1. 我以应用管理员(普通用户)身份登录 Facebook。

  2. 我到了 FB.getLoginStatus 返回 response.status === 'not_authorized' 的地步。

    1. 我打电话给 FB.login。
    2. 我收到一个弹出窗口说“发生错误。请稍后再试。”

    3. FB.login 使用 response.authResponse = null 回调。

    4. 控制台日志显示“LOG:找不到回调 1”。

我在所有浏览器中都遇到相同的错误...帮助?

Here is the relevant code - I replaced actual strings by ######:

<div id="fb-root"></div>

<script>

var init_status = 1;
var login_status = 1;
var signedRequest = ' ';

window.fbAsyncInit = function() {
  FB.init({
    appId      : '######', // App ID from the App Dashboard
    channelUrl : 'http://#####/channel.php', // Channel File for x-domain communication
    status     : true, // check the login status upon init?
    cookie     : true, // set sessions cookies to allow your server to access the session?
    xfbml      : false  // parse XFBML tags on this page?
  });
  getLoginStatus();
};

// Load the SDK Asynchronously:
(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));

call_proceed1_when_ready(); // wait for init_status > 1

function proceed1() {

  // Login the user and/or authenticate with app, if necessary:
  if (init_status > 2) {
    login ();
  } else {
    login_status = 2;
  }

  call_proceed2_when_ready(); // wait for login_status > 1

} //proceed1

function proceed2() {

  alert('DONE');

} //proceed2

////////////////
// FUNCTIONS: //
////////////////

function call_proceed1_when_ready () {
  if (init_status > 1) {
    proceed1();
  } else {
    setTimeout(call_proceed1_when_ready, 500); // 0.5 second
  }
}

function call_proceed2_when_ready () {
  if (login_status > 1) {
    proceed2();
  } else {
    setTimeout(call_proceed2_when_ready, 500); // 0.5 second
  }
}

function getLoginStatus() {
  FB.getLoginStatus(function(response) {
    if (response.status === 'connected') {
      signedRequest = response.authResponse.signedRequest;
      init_status = 2;
    } else if (response.status === 'not_authorized') {
      init_status = 3;
    } else {
      init_status = 4;
    }
  });
}

function login() {
  FB.login(function(response) {
    if (response.authResponse) {
      login_status = 2;
    } else {
      login_status = 3;
    }
  });
}

</script>
4

0 回答 0