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 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误