当我删除cookie时,Facebook网站应用程序无限循环:来自FB.init的真实参数

时间:2012-03-08 00:21:21

标签: php javascript facebook

可能是一个愚蠢的问题,但这将帮助我了解FB整合。

我使用标准FB.init来使用javascript SDK,并使用PHP SDK进行一些基本的API调用:

    FB.init({
  appId      : '265236093556723', // App ID
  status     : true, // check login status
 // cookie     : true, // enable cookies to allow the server to access the session. WHY IS THERE AN INFINITE LOOP WHEN THIS IS REMOVED?!?!?!?!?!
  xfbml      : true,  // parse XFBML
  oauth      : true,
  channelUrl : 'http://www.loveweber.co.uk/dev/fbchannel.php' // Channel File

});

我正在测试内容并注释掉了cookie:true line。这导致网站循环实现页面的编码,我不知道为什么。我到处读到PHP使用Javascript设置的这个cookie ...所以它是否与PHP调用API有关?

或者可能与某些事情有关:

        FB.Event.subscribe('auth.login', function(response) {
        window.location.reload(); // When user logs in, the page refreshes...
        });
    FB.Event.subscribe('auth.logout', function(response) {
          window.location.reload();
        });

用户登录或退出时页面的实时编码?

谢谢你会帮助很多。

1 个答案:

答案 0 :(得分:1)

FB.Event.subscribe('auth.login', function(response) {
    window.location.reload(); // When user logs in, the page refreshes...
});
FB.Event.subscribe('auth.logout', function(response) {
      window.location.reload();
});

我注意到你没有在任一事件订阅中检查响应变量。你应该确保在你盲目地进行reload()之前你的反应是你的想法; Facebook向您发送响应对象的原因是因为它并不总是您的想法。

响应对象如下:

     {
       status: "xxx",         /* Current status of the session */
       authResponse: {          /* Information about the current session */
          userID: ""          /* String representing the current user's ID */
          signedRequest: "",  /* String with the current signedRequest */
          expiresIn: "",      /* UNIX time when the session expires */
          accessToken: "",    /* Access token of the user */
       }
     }

所以当你订阅auth.login时,请确保response.status是'connected'。然后在订阅auth.logout时没有“连接”。