Php 使用Phalcon登录Facebook时重定向过多

Php 使用Phalcon登录Facebook时重定向过多,php,facebook,authentication,phalcon,Php,Facebook,Authentication,Phalcon,我们的facebook身份验证有问题。我们使用phalcon,并使用php-sdk-v4插件进行身份验证。当我们尝试登录时,会出现重定向过多的错误。我们的网站是。要帮忙吗 代码: 文件:AUTH.PHP public function loginWithFacebook() { $di = $this->getDI(); $facebook = new FacebookConnector($di); $facebookUser = $facebook->ge

我们的facebook身份验证有问题。我们使用phalcon,并使用php-sdk-v4插件进行身份验证。当我们尝试登录时,会出现重定向过多的错误。我们的网站是。要帮忙吗

代码: 文件:AUTH.PHP

public function loginWithFacebook()
{
    $di = $this->getDI();
    $facebook = new FacebookConnector($di);

    $facebookUser = $facebook->getUser();
    if (!$facebookUser) {
        $scope = [
            'scope' => 'email,user_birthday,user_location',
        ];

        return $this->response->redirect($facebook->getLoginUrl($scope), true);
    }
    try {
        return $this->authenticateOrCreateFacebookUser($facebookUser);
    } catch (\FacebookApiException $e) {
        $di->logger->begin();
        $di->logger->error($e->getMessage());
        $di->logger->commit();
        $facebookUser = null;
    }
}
FACEBOOKCONNECTOR.PHP

public function __construct($di)
{

    $this->di = $di;
    $fbConfig = $di->get('config')->pup->connectors->facebook;

    $protocol = strtolower(substr($_SERVER['SERVER_PROTOCOL'], 0, strpos($_SERVER['SERVER_PROTOCOL'], '/'))).'://';
    $protocol="https://";

    if (isset($fbConfig['route'])) {
        $this->url = $protocol.$_SERVER['HTTP_HOST'].$fbConfig['route'];
    } else {
        $this->url = $protocol.$_SERVER['HTTP_HOST'].'/usercontrol/loginwithfacebook';
    }
    //echo $this->url;die();


    FacebookSession::setDefaultApplication($fbConfig->appId, $fbConfig->secret);
}

public function getLoginUrl($scope = [])
{
    $this->helper = new FacebookRedirectLoginHelper($this->url);

    return $this->helper->getLoginUrl($scope);
}

/**
 * Get facebook user details.
 *
 * @return unknown|bool
 */
public function getUser()
{
    try {
        $this->helper = new FacebookRedirectLoginHelper($this->url);
        $this->fb_session = $this->helper->getSessionFromRedirect();
    } catch (FacebookRequestException $ex) {
        $this->di->get('flashSession')->error($ex->getMessage());
    } catch (\Exception $ex) {
        $this->di->get('flashSession')->error($ex->getMessage());
    }

    if ($this->fb_session) {
        $request = new FacebookRequest($this->fb_session, 'GET', '/me?fields=id,first_name,last_name,email');
        $response = $request->execute();
        $fb_user = $response->getGraphObject()->asArray();
        return $fb_user;
    }

    return false;
}
USERCONTROLLER.PHP

public function loginwithfacebookAction()
{
    try {
        //echo "dentro del try";
        $this->view->disable();
        $fopen = fopen('../logs/loginWithFacebook.log');
        fwrite( $this->auth->loginWithFacebook() , $fopen );
        fclose( $fopen );
        return $this->auth->loginWithFacebook();
    } catch(AuthException $e) {
        $this->flash->error('There was an error connectiong to Facebook.');
    }
}

我无法测试它,但它似乎是循环的:在
facebookconnector.php
中,if导致对静态函数
FacebookSession::setDefaultApplication
的相同调用。你可以尝试:

if (isset($fbConfig['route'])) {
    $this->url = $protocol.$_SERVER['HTTP_HOST'].$fbConfig['route'];
    FacebookSession::setDefaultApplication($fbConfig->appId, $fbConfig->secret);
} else {
    $this->url = $protocol.$_SERVER['HTTP_HOST'].'/usercontrol/loginwithfacebook';
    return $this->response->redirect($this->url);
}

是的,你需要没有任何代码、配置或日志的帮助吗?对不起,我发布了代码没有人想下载某人的(错误代码)文件。使用编辑器并在此处编写代码。这样你将有更多的机会得到适用的答案。