dongyi1996 2012-07-25 20:54
浏览 264
已采纳

facebook app多次登录,逻辑错误

I have this facebook app to show fb notifications in my website. Then i had this problem, Assume two users Alice & Bob. Alice is my website's regular user and she recommended it to Bob. She made him register on to my site from her own laptop. When bob tried to add the app, Alice's fb notifications shown up. Actually when Bob clicked the login link, since alice was already logged onto facebook it just pulled her details (same session), how to tackle this situation, Do we have to make Alice logout from facebook and make Bob login, Something like "Alice already logged in, sign in as a different user", Could somebody please suggest some solutions and how to do it.

The following is the piece of code am using for login

        require_once('sdk/src/facebook.php');

        $facebook = new Facebook(array(
          'appId'  => 'xxxxxxxxxxxxxxxx',
          'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
          'cookie' => true
        ));


        // Get User ID
        $user = $facebook->getUser();


        // Login or logout url will be needed depending on current user state.
        if ($user) {
          $logoutUrl = $facebook->getLogoutUrl();
        } else {
          $loginUrl = $facebook->getLoginUrl();
        }


        //check permissions list

        if ($user) {
            $permissions_list = $facebook->api('/me/permissions','GET', array('access_token' => $access_token));


             //check if the permissions we need have been allowed by the user
            //if not then redirect them again to facebook's permissions page
            //
            $permissions_needed = array('manage_notifications','publish_stream', 'read_stream');
            $login_url_params = array(
                        'scope' => 'manage_notifications,publish_stream,read_stream',
                        'fbconnect' =>  1,
                        'display'   =>  "page",
                        'next' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']
                    );
            foreach($permissions_needed as $perm) {
                if( !isset($permissions_list['data'][0][$perm]) || $permissions_list['data'][0][$perm] != 1 ) {
                    $login_url_params = array(
                        'scope' => 'manage_notifications,publish_stream,read_stream',
                        'fbconnect' =>  1,
                        'display'   =>  "page",
                        'next' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']
                    );
                    $login_url = $facebook->getLoginUrl($login_url_params);
                    echo $login_url;
                    header("Location: {$login_url}");
                    exit();
                }
            }               

            //if the user has allowed all the permissions we need,
            //get the information about the pages that he or she managers
            $accounts = $facebook->api(
                '/me',
                'GET',
                array(
                    'access_token' => $access_token
                )
            );              
        } 

          else {
            //if not, let's redirect to the ALLOW page so we can get access
            //Create a login URL using the Facebook library's getLoginUrl() method
            $login_url_params = array(
                'scope' => 'manage_notifications,publish_stream,read_stream',
                'fbconnect' =>  1,
                'display'   =>  "page",
                'next' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']
            );
            $login_url = $facebook->getLoginUrl($login_url_params);

            //redirect to the login URL on facebook
            $facebook_login = $login_url;
             echo "<a href='$login_url'>Login Facebook</a>";
  • 写回答

2条回答 默认 最新

  • dongliang9576 2012-07-25 21:20
    关注

    The best thing to do would be the following:

    1. When a user comes to your site, detect whether they are logged into Facebook and whether they are auth'd for your app using the Javascript SDK and the FB.getLoginStatus method.
    2. If they aren't auth'd, prompt them with the Permissions dialog and encourage them to sign up.
    3. If they are auth'd and logged in to FB, then automatically log them into your website. To avoid the Alice/Bob confusion, show an indicator somewhere on your website that they've been logged in as "Alice" and maybe have a link underneath that says 'Not you? Click here to login as someone else' or similar
    4. If they click on this link, or they click on a Logout link on your site call the FB.logout method in the Javascript SDK which will invalidate the current access token for that user but also log them out of Facebook.

    Then, you can push them back to the login/registration page after this and they will be prompted to login to their Facebook account.

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

报告相同问题?

悬赏问题

  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。