1

私は webtechnick Facebook プラグインを使用しており、PHP サイトとの統合に成功しました。ログインとログアウトは正常に機能していますが、あるタブで Facebook にログインし、別のタブで Web サイトにログインすると問題が発生します。

この場合、私の Web サイトは、ログイン ページの Facebook ログイン ボタンをクリックしなくても、Facebook データを自動的に取得します。Web サイトは、ログイン ページで Facebook ログイン ボタンをクリックした場合にのみ、Facebook データを取得する必要があります。どうすればこれを解決できますか?

FacebookHelper.php の私のコードは次のとおりです。

public function init($options = null, $reload = true) {
        $options = array_merge(array(
            'perms' => 'email'
        ), (array)$options);
        if ($appId = FacebookInfo::getConfig('appId')) {
            $init = '<div id="fb-root"></div>';
            $init .= $this->Html->scriptBlock("
    window.fbAsyncInit = function() {
        FB.init({
            appId      : '$appId', // App ID
            channelURL : '../../Vendor/channel.php', // Channel File
            status     : true, // check login status
            cookie     : true, // enable cookies to allow the server to access the session
            oauth      : true, // enable OAuth 2.0
            xfbml      : true  // parse XFBML
        });


        // Checks whether the user is logged in
        FB.getLoginStatus(function(response) {
            if (response.authResponse) {
                // logged in and connected user, someone you know
                // alert('You are connected');
            } else {
                // no user session available, someone you dont know
                // alert('You are disconnected');
            }
        });

        FB.Event.subscribe('auth.authResponseChange', function(response) {
            if (response.authResponse) {
                // the user has just logged in
                // alert('You just logged in facebook from somewhere');
            } else {
                // the user has just logged out
                // alert('You just logged out from faceboook');
            }
        });



        // Other javascript code goes here!

    };

    // logs the user in the application and facebook
    function login(redirection){
        FB.login(function (response) {
            if(response.authResponse) {
                // user is logged in
                // console.log('Welcome!');
                if(redirection != null && redirection != ''){
                    top.location.href = redirection;
                }
            } else {
                // user could not log in
                console.log('User cancelled login or did not fully authorize.');
            }
        }, {scope: '" . $options['perms'] . "'});
    }

    // logs the user out of the application and facebook
    function logout(redirection){
        FB.logout(function(response) {
            // user is logged out
            // redirection if any
            if(redirection != null && redirection != ''){
                top.location.href = redirection;
            }
        });
    }

    // Load the SDK Asynchronously
    (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol 
    + '//connect.facebook.net/".$this->locale."/all.js';
    document.getElementById('fb-root').appendChild(e);
    }());");
            return $init;
        } else {
            return "<span class='error'>No Facebook configuration detected. Please add the facebook configuration file to your config folder.</span>";
        }
    }

ログインページ (login.ctp):

 <?php 
    echo $this->Facebook->html();

        echo $this->Facebook->login(array('id'=>'facebookbut','img' => 'facebooklogin.png','redirect' =>'/'));

    echo $this->Facebook->init();
    ?>
4

0 に答える 0