getLoginStatus和getAuthResponse在IE中不起作用

时间:2012-02-07 17:14:09

标签: facebook browser

我在Facebook文档和StackOverflow中搜索过,并且没有一个可行的解决方案适合我。当页面没有加载到canvas iFrame中时,代码可以在Firefox和Chrome中运行,甚至可以在Internet Explorer中运行,但在app canvas iFrame中,这些函数从不调用它的回调,因此getUserDatafbAskAuth()都不会调用。正如你所看到的,我填充了channelUrl参数。这是我的代码:

var fb = {};

fb = function(){

  var pub = {};
  var priv = {};
  var base_url = '{base_url}';

  //atributes
  pub.user = {};
  pub.token = {};

  //methods
  pub.init = function(callback)
  {
      //When the library has loaded, it calls this function
      window.fbAsyncInit = function() {

        //Facebook jsSDK inizalization
        FB.init({
          appId  : '{app_id}',
          channelUrl: base_url + 'res/channel.php',
          status : true, // check login status
          cookie : true, // enable cookies to allow the server to access the session
          xfbml  : true,  // parse XFBML
          oauth: true
        });

        //Resize the iframe
        FB.Canvas.setSize({ width: 760, height: ($('body').outerHeight(true) + 50) });

        // Check for the user session
        FB.getLoginStatus(function(response){
            if (response.status === 'connected')
            {
                // This user has already authorized the app
                priv.getUserData(response, callback);
            }
            else
            {
               // No user session available, this is a new user to the app
               // or a user not logued in facebook
               priv.fbAskAuth(callback);
           }
        });

      };

      //Asyncronous get of facebook library.
      (function() {
        var e = document.createElement('script');e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/es_ES/all.js';
        document.getElementById('fb-root').appendChild(e);
      }());

  };

  pub.inviteSendGeneral = function()
  {
      FB.ui({
                method: 'apprequests',
                message: pub.user.name+' te ha invitado a participar en La Porra de GOLT.',
                data: 'tracking info'
            }, function(requests){
                $.ajax({
                       url: base_url + 'ajax/invite/',
                       type: 'post',
                       data: {fuid: pub.user.id, invitation: requests },
                       success: function(resp)
                       {
                           $('#help-msg').html(resp);
                       }
                  });
            });
  }

  pub.inviteSend = function()
  {
      FB.ui({
                method: 'apprequests',
                message: pub.user.name+' te ha invitado a participar en una porra.',
                data: 'tracking info'
            }, function(requests){
                if(requests !== undefined)
                {
                    for(var i=0; i<requests.request_ids.length; i++)
                    {
                        FB.api(requests.request_ids[i], {access_token: pub.user.access_token}, function(request_obj){

                            $.ajax({
                                   url: base_url + 'ajax/friends_invite/',
                                   type: 'post',
                                   data: {fuid: pub.user.id, invitation: request_obj.id, invited: request_obj.to.id, round: pub.getId($('.invite-friends').attr('id'))},
                                   success: function(resp){
                                       $('#help-msg').html(resp);
                                   }
                              });
                        });
                    }
                }
            });
  }

  priv.getUserData = function(response, callback)
  {
     FB.api('/me', {access_token: response.authResponse.accessToken}, function(user_data) {

        if(user_data.id != '0'){
            pub.user = user_data;
            pub.token = response.authResponse.accessToken;
            callback.call();
        }else{
            priv.fbAskAuth(callback);
        }
     });
  };

  pub.checkLikes = function(likes, page_id)
  {
          //var likes = $.parseJSON(data);
          for(var i=0; i<likes.data.length; i++)
          {
            if(likes.data[i].id == page_id){
                return true;
            }
          }
      return false;
  }

  priv.fbAskAuth = function(callback)
  {
    FB.login(function(response) {
      if (response.status === 'connected') {

          priv.getUserData(response, callback);

      } else {
        // user is not logged in
        priv.fbAskAuth(callback);
      }
    }, {scope:'{app_perms}'});
  };

  pub.array2str = function(requests)
  {
    var result_str = '';
    for(var i=0; i < requests.length; i++)
    {
        if(i == requests.length-1)
            result_str = result_str + requests[i];
        else
            result_str = result_str + requests[i] + ',';
    }

    return result_str;
  };

  pub.getId = function(str)
  {
    var id_array = str.split('_');
    return id_array[id_array.length-1];
  };

  return pub;

}();

在另一个js文件中,我调用fb.init以及包含其他对象和函数。一切正常,除了没有调用其回调的getLoginStatus

$(document).ready(function(){

    fb.init(function(){
        if($('.penaltis').length > 0)
        {
            loadFriends();
        }
    });

});

任何提示都将不胜感激,谢谢。

1 个答案:

答案 0 :(得分:0)

我认为在大多数情况下有两个典型问题会造成麻烦。第一个是,Facebook无论如何都用https调用你的应用URL。第二是忘记定义。您是否使用https://?

检查了您的网页