Facebook oauth rest api使用opencart重定向uri问题

I have to implement authorization with Google and Facebook on OpenCart website. I have no problems with Google rest api, but some with Facebook. So, oauth rest api method is pretty simple.

<?php
  $client_id = APP_ID; // Client ID
  $client_secret = APP_SECRET; // Client secret
  $redirect_uri = 'https://example.com/facebook-login/index.php'; // Redirect URIs

  $url = 'https://www.facebook.com/v2.9/dialog/oauth';
    
    $params = array(
        'client_id'     => $client_id,
        'redirect_uri'  => $redirect_uri,
        'response_type' => 'code',
        'scope'         => 'email'
    );

    if (isset($_GET['code'])) {

        $params = array(
            'client_id'     => $client_id,
            'redirect_uri'  => $redirect_uri,
            'client_secret' => $client_secret,
            'code'          => $_GET['code']
        );
    
        $url = 'https://graph.facebook.com/oauth/access_token';

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, urldecode(http_build_query($params)));
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        $result = curl_exec($curl);
        curl_close($curl);
        $tokenInfo = json_decode($result, true);
        
        echo '<pre>';
        print_r($tokenInfo);
        echo '</pre>';

        if (count($tokenInfo) > 0 && isset($tokenInfo['access_token'])) {
            $params = array('access_token' => $tokenInfo['access_token']);
            $params = array(
                'fields' => 'id,name,email', 
                'access_token' => $tokenInfo['access_token']
            );
    
            $userInfo = json_decode(file_get_contents('https://graph.facebook.com/me' . '?' . urldecode(http_build_query($params))), true);
    
            if (isset($userInfo['id'])) {
                echo '<pre>';
                print_r($userInfo);
                echo '</pre>';
            }
        }

    } else {
        
        $loginUrl = $url . '?' . urldecode(http_build_query($params));
        header('Location: ' . filter_var($loginUrl, FILTER_SANITIZE_URL));
    }

And this code works fine until your redirect uri link does not contain OpenCart's "route" params or something like this!

So, if my $redirect_uri variable equals "https://example.com/facebook-login/" it's ok. But when I try to implement this script on any of openCart's page (for e.g. "https://example.com/index.php?route=account/login/facebook") it fails because Facebook oauth api throws exception: "Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request".

I tried to encode slashes but to no avail. So why Google rest api works fine with this redirect uri but Facebook doesn't? Why does it have very strict rules?

Could somebody help me please to solve this problem?

</div>