dtg25862 2013-11-17 16:45
浏览 71

Facebook PHP SDK - getUser()从Facebook注销后返回有效的userId

I'm putting a "Login with Facebook" option in a website and I managed to achieve it quite smoothly. I'm relying in facebook->getUser() method which, according to the documentation, returns the Facebook User ID of the current user, or 0 if there is no logged-in user. However, after logging in, all subsequent calls to getUser() return the userId, even if I go manually to facebook and logout. Seems like the userId is being cached or something. I can see many people with the same issue but still could't find a solution for this. How can I overcome this issue (the website is based in CodeIgniter and I'm referring to this tutorial)?

  • 写回答

1条回答 默认 最新

  • douxia9826 2013-11-19 23:45
    关注

    Copy paste from my website.

        $user = $this->facebook->getUser();
    
        // We may or may not have this data based on whether the user is logged in.
        //
        // If we have a $user id here, it means we know the user is logged into
        // Facebook, but we don't know if the access token is valid. An access
        // token is invalid if the user logged out of Facebook.
        $profile = null;
        if($user)
        {
            try {
                // Proceed knowing you have a logged in user who's authenticated.
                $profile = $this->facebook->api('/me?fields=id,name,link,email');
            } catch (FacebookApiException $e) {
                error_log($e);
                $user = null;
            }
        }
    

    See how $user goes to null if the API doesn't respond? That's the key. If you don't go through that step, it wont work. getUser will sometimes return an ID even if the user recently logged out.

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料