Error using Facebook login again and again

3

I'm using the Facebook API to register data in the database. As soon as I open and navigate everything works fine, but when I try to register more than once this error appears:

AfterIclosethebrowseritreturnstonormal,soIbelieveitisaproblemreadingthedatainSESSION.Hereismycode:

<?phpsession_start();include_once("php/conexao.php");
    require_once __DIR__ . '/lib/Facebook/autoload.php';

    $fb = new \Facebook\Facebook([
      'app_id' => '**********',
      'app_secret' => '**************',
      'default_graph_version' => 'v2.10',
      ;

    $helper = $fb->getRedirectLoginHelper();
    //print_r($helper);
    $permissions = ['email'];

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

    if(!isset($accessToken)){
        $url_login = 'https://fidecard.net/conclui_cadastro_cliente.php';
        $loginUrl = $helper->getLoginUrl($url_login, $permissions);
    }else{
        $url_login = 'https://fidecard.net/conclui_cadastro_cliente.php';
        $loginUrl = $helper->getLoginUrl($url_login, $permissions);

        if(isset($_SESSION['face_access_token'])){
            $fb -> setDefaultAccessToken($_SESSION['face_access_token']);
        }else{
            $_SESSION['face_access_token'] = (string)$accessToken;
            $oAuth2Client = $fb -> getOAuth2Client();
            $_SESSION['face_access_token'] = $oAuth2Client->getLongLivedAccessToken($_SESSION['face_access_token']);
            $fb->setDefaultAccessToken($_SESSION['face_access_token']);
        }


        try {
            // Returns a 'Facebook\FacebookResponse' object
            $response = $fb->get('/me?fields=name, email');
            $user = $response->getGraphUser();
            $nome_cliente = $user['name'];
            $email_cliente = $user['email'];
            $cpf_cliente = $_SESSION['cpf_cliente'];

            $result = "UPDATE cliente SET email_cliente = '$email_cliente', nome_cliente = '$nome_cliente', confirma_email_cliente = true WHERE cpf_cliente = '$cpf_cliente'";
            $resultado = mysqli_query($link, $result);          
        } catch(Facebook\Exceptions\FacebookResponseException $e) {
          echo 'Graph returned an error: ' . $e->getMessage();
          exit;
        } catch(Facebook\Exceptions\FacebookSDKException $e) {
          echo 'Facebook SDK returned an error: ' . $e->getMessage();
          exit;
        }
    }
?>
    
asked by anonymous 02.04.2018 / 15:02

0 answers