Facebook PHP SDK没有读取cookie值

I'm pretty new to Facebook SDK, but I'm trying to implement Facebook authentication, so I do that using both Javascript SDK and PHP SDK and using Javascript Helper as shown on docs, but this doesn't work, as this returns the message no access token found, but I have checked and cookie IS generated, what could be the problem?

JAVASCRIPT

window.fbAsyncInit = function () {
    FB.init({
        appId: 'xxxxxxxx',
        cookie: true,
        version: 'v2.5'
    });
    FB.getLoginStatus(function (response) {
        if (response.status === 'connected') {
            $('#fb-login').text('Conexion autorizada').off('click');
        } else if (response.status === 'not_authorized') {
            $('#fb-login').removeClass('disabled').text('Autorizar App');
        } else {
            $('#fb-login').removeClass('disabled').on('click');
        }
    });
};
(function (d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id))
        return;
    js = d.createElement(s);
    js.id = id;
    js.src = "//connect.facebook.net/es_LA/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

$('#fb-login').click(function () {
    FB.login(function (response) {
        if (response.authResponse) {
            FB_Auth();
        } else {
            alert('Inicio de sesión cancelado o no autorizado');
        }
    }, {scope: 'user_posts,email,contact_email,publish_actions,public_profile', return_scopes: true});
});

function FB_Auth() {
    $.ajax({
        url: 'auth/fb_login.php',
        method: 'POST',
        data: {action: 'login'},
        success: function (server_response) {
            console.log("La respuesta fue: 
" + server_response);
            if (server_response === 'ok') {
                window.location.href = "appmenu.php";
            }
        },
        error: function (server_response) {
            console.log("Error en respuesta servidor:" + server_response);
        }
    });
}

And the PHP the AJAX function calls

PHP

    <?php
    require '../controladoras/globals.php';
    require '../Facebook/autoload.php';

    $action = filter_input(INPUT_POST, 'action', FILTER_SANITIZE_STRING);

    $fb = new Facebook\Facebook([
        'app_id' => 'xxxxxxxxx',
        'app_secret' => 'xxxxxxxxxxxx',
        'default_graph_version' => 'v2.5',
            ]);

    $helper = $fb->getJavaScriptHelper();

    try {
        $accessToken = $helper->getAccessToken();
    } catch (Facebook\Exceptions\FacebookResponseException $e) {
        // When Graph returns an error
        echo ('Graph returned an error: ' . $e->getMessage());
    } catch (Facebook\Exceptions\FacebookSDKException $e) {
        // When validation fails or other local issues
        echo ('Facebook SDK returned an error: ' . $e->getMessage());
    }


   if (! isset($accessToken)) {
  echo 'No cookie set or no OAuth data could be obtained from cookie.';
  exit;
    } else {
        var_dump($accessToken->getValue());
        $fb_auth = new Sesiones();
        switch ($action) {
            case 'login':
                $params = [["param" => "authLvl", "val" => 1], ["param" => "fb_access_token", "val" => (string) $accessToken]];
                $fb_auth->IniciarSesion($params);
                echo ('ok');
                break;
            case 'logout';
                $fb_auth->CerrarSesion();
                exit;
                break;
        }
    }
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问