1

fbconnect の自動ログインで User 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>

フェイスブック 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 にログインしている場合、認証されていない facebook で何度も memeber/fbconnect にリダイレクトされます。

4

0 に答える 0