1

我正在尝试在我的 facebook 应用程序中对用户进行身份验证。我正在使用以下代码:

window.fbAsyncInit = function () {
        FB.Event.subscribe('auth.statusChange', fbIsReady);
        FB.init({ appId: app_id, channelUrl: channelUrl, status: true, cookie: true, xfbml: true, oauth: true});
        FB.Canvas.setAutoGrow();
        FB.Canvas.scrollTo(0, 0);
      };

      (function (d) {
        var js, id = 'facebook-jssdk'; if (d.getElementById(id)) { return; }
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_GB/all.js";
        d.getElementsByTagName('head')[0].appendChild(js);
      } (document));


function fbIsReady(res){
  fbReady = 1;
  var params = {method: "oauth", "scope": 'publish_stream'};
  FB.ui(params, isLoggedIn);
}

function isLoggedIn(res){
  if(!res || res.status === 'not_authorized' || res.perms != 'publish_stream')
    fbIsReady();
  else if(res.hasOwnProperty('selected_profiles')){
    FB.api('/me', {access_token: FB.getAccessToken()}, checkUserInfo);
  }
}

function checkUserInfo(){
    console.log(res); // return the error bellow right after the user gives permissions and the expected result after refresh
}

我的问题是,用户在应用程序中进行身份验证后,未设置访问令牌。我需要刷新页面才能正常工作。我认为在用户授权后我将能够执行 FB.api('/me'...) 但我得到:

代码:2500 消息:“必须使用活动访问令牌来查询有关当前用户的信息。” 类型:“OAuthException”

直到我刷新页面。任何想法??

谢谢

4

0 回答 0