dqfkd82886 2011-06-23 14:38
浏览 156
已采纳

Facebook PHP SDK getUser()方法甚至在从Facebook取消授权应用程序后返回uid

I'm writing a web app that uses facebook's PHP SDK. I'm using the getUser() method to authenticate users similar to this:

    $user = $this->facebook->getUser();
    $loginUrl = $this->facebook->getLoginUrl(array(
        'scope' => 'email,publish_stream',
        'redirect_uri' => base_url() . 'index.php/welcome/create'
    ));;

    if(!$user){
        /*
         * User not authenticated, present with facebook authorize dialog
         * */
        echo "<script type='text/javascript'>window.location = '$loginUrl';</script>";
        die();

What I don't understand is why getUser() continues to return my facebook uid even after I've removed the app from my facbeook privacy settings in facebook. Anyone know why?

  • 写回答

5条回答 默认 最新

  • dongnanman9093 2011-06-23 18:13
    关注

    This is because the user id is still in the session!

    This is mainly causing an error when making calls with the me object (active access token is needed, or something like that).

    One way to over come this would be:

    try {
        $user_profile = $this->facebook->api('/me');
    } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
        if(DESIRED_ERR_NUM && session_id()) {
            session_destroy(); // OR UNSET FB RELATED VARS ONLY
        }
        echo '<script>top.location.href = "' .  $this->facebook->getLoginUrl(array("scope"=>"publish_stream,user_about_me","redirect_uri"=>"YOUR_URL_HERE")) . '"</script>';
        exit;
    }
    

    This is NOT a working code, you need to check the error number AND if you have a session then destroy it OR just unset Facebook related vars in it.

    You can check if this is true by executing:

    if(session_id()) {
        session_destroy();
    }
    

    (please note that this will destroy EVERYTHING in the session not only Facebook related stuff!)

    As I said this is not a working code but hopefully it will get you started (this can definitely be enhanced, pushed to the Facebook class..etc).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大