自动登录FBConnect问题

时间:2013-01-24 06:50:29

标签: php facebook session fbconnect

fbconnect中的自动登录无法识别用户Session.javascript代码

    <div id="fb-root"></div>
<script type="text/javascript">

var flag=0;

var fbLogin = "<?php echo $this->Session->read('FBLoginID')?>";
var sLogin = "<?php echo $this->Session->read('LoginID')?>";
var FB_APP_ID = "<?php echo FB_APP_ID;?>";
var SITE_URL = "<?php echo SITE_URL;?>";


            window.fbAsyncInit = function() {
                FB.init({appId: FB_APP_ID, status: true, cookie: true, xfbml: true, oauth:true});

                /* All the events registered */
                FB.Event.subscribe('auth.login', function(response) {
                    // do something with response
                    login();
                });
                FB.Event.subscribe('auth.logout', function(response) {
                    // do something with response
                    logout();
                });

                if(FB.getUserID()) { 
                    if(sLogin==""){
                      if(fbLogin==""){
                        //document.location.href = SITE_URL+"/members/fbconnect";
                window.location = SITE_URL+"members/fbconnect";
                      }
                    }
                }
            };
            (function() {
                var e = document.createElement('script');
                e.type = 'text/javascript';
                e.src = document.location.protocol +
                    '//connect.facebook.net/en_US/all.js';
                e.async = true;
                document.getElementById('fb-root').appendChild(e);
            }());

            function login(){
                if(!sLogin)
                    window.location = SITE_URL+"members/fbconnect";
            }
            function logout(){
                window.location = SITE_URL+"/homes/logout";
            }

function LogoutFB(){FB.logout(SITE_URL+'/homes/logout');}

</script>
<div id="fancy-facebook" class="mobil-sprite">
<p class="fancy-facebook-heading">Sign-in <span class="grey">with facebook</span></p>
<div style="clear:both;height:5px;"></div>
<div style="margin:20px auto;width:94px;">
<fb:login-button autologoutlink="true" scope="user_photos,friends_photos,email,user_birthday,status_update,publish_stream">Connect</fb:login-button>
</div>
</div>

Facebook PHP代码

<?php

require_once 'facebook/fb/facebook.php';

class FacebookConnectComponent extends Object  {

    var $components = array('Session','Session');

    var $facebook;
    var $__fbId = FB_APP_ID;
    var $__fbApiKey = FB_APP_ID;
    var $__fbSecret = FB_SECRET_KEY;

    var $loginUrl = '/members/fbconnect';
    var $logoutUrl = '/members/logout';

    var $session;
    var $user;
    var $fbme;

     function startup(&$controller) {

        $this->facebook = new Facebook(array(
          'appId'  => $this->__fbId,
          'secret' => $this->__fbSecret,
          'cookie' => true
        ));

  //$this->session = $this->facebook->getSession();
    $this->user = $this->facebook->getUser();
    $this->fbme = null;
    // Session based graph API call.
    //if ($this->session) {
     if($this->user){
      try {
        $uid = $this->user;
        $this->fbme = $this->facebook->api('/me');
      } catch (FacebookApiException $e) {
          //$this->d($e);
           // $login_url = $this->facebook->getLoginUrl();
   // header("Location: ".$login_url); 
      }
    }//else{ echo "test";die; }
    //new code
    // if(!$this->user) { //Ask for bare minimum login
    // $login_url = $this->facebook->getLoginUrl();
   // header("Location: ".$login_url); 
    // }
    //end of code

    function d($d){
        echo '<pre>==';
        print_r($d);
        echo '</pre>';
    }

    function getlogout(){

        return $this->facebook->getLogoutUrl();
    }

    }
 }

?>

如果用户已经登录facebook.It一次又一次地重定向到memeber / fbconnect,并且facebook没有授权。

0 个答案:

没有答案