doucheyi1347 2012-08-23 07:56
浏览 42
已采纳

Facebook登录/注销/检查PHP类中由PHP-SDK提供支持的用户

I have PHP-Class to work with Facebook API:

class Social {
   private $name;
   private $context;
   private $tocken;

   public function check(){
     $this->tocken = $this->context->getAccessToken(); // get current tocken
     if (isset($_SESSION['fb_tocken']) AND !empty($_SESSION['fb_tocken'])){
        // session tocken not null
        if ($_SESSION['fb_tocken'] == $this->tocken){
           // session tocken = current tocken
           // update last active
           return true;
        } elseif ($this->tocken == APPLICATION_TOCKEN) {
          // current tocken == default tocken
          $this->logout();
        } else {
          // current tocken <> default tocken
          $this->logout();
        }
     } else {
        // session tocken is null
        if ($this->tocken == APPLICATION_TOCKEN){
          // current tocken is default
          return false;
        } else {
          // current tocken is not default
          if ($this->getUserInfo()){
             // user registered - login action
             if ($this->login())
                return true;
             else
                return false;
          } else {
             // register new user
             if ($this->register()){
                if ($this->login()){
                   return true;
                } else
                   return false;
             } else
                return false;
          }
        }
  }
   }
   // ...
};

If user used alogritm:

1 - Login in facebook 2 - Login in application 3 - Logout from facebook 4 - Login in facebook 5 - Open application

Application Problem:

after fifth step my app can't authorize a user. But if user press 'refresh' he become authorized.

  • 写回答

1条回答 默认 最新

  • douyi02577 2012-08-23 08:40
    关注

    That is the correct behviour - but impossible to confirm without the rest of your code (i.e. the bit that grabs the token).

    What happens is that when a user logs out, the current token (that you have stored in your session) becomes invalid. The user logs back into Facebook, you need to get the new token, and that's not going to happen automtically - but when you do a refresh, I presume your code getAccessToken() (not shown above) will grab the new token.

    The simplest fix is to add a listener in Javascript for logging in and out. You can find the details here and you need the auth.login handler. When you have that triggered, simply refresh the page.

    There are other options using Javascript tot pump the new token to a PHP listener that can update your session behind the scenes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动