Facebook login php Auth returning dialog/oauth? client_id in url

Asked

Viewed 543 times

5

I’m making my application to login on Facebook, but it returns with GET on the url ?code=etc...

Before it was working normally, I use via class from Facebook. See:

    $facebook = new Facebook(array(
        'appId' => APP_ID,
        'secret' => APP_SECRET,
    ));

    $user = $facebook->getUser();
    #$facebook->setAccessToken($_REQUEST['access_token']);
    if($user){
      try {
        $user_profile = $facebook->api('/me', 'GET');
      } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
      }
    }

To log in I am using the following option:

# There's no active session, let's generate one
$login_url = $facebook->getLoginUrl(array(
    'scope'  => 'email, user_about_me, user_friends, 
                 user_birthday, publish_actions, read_stream, user_website',
    'redirect_uri' => 'http://www.rifao.com.br/facebook/'
));
header("Location: " . $login_url);

The problem is that at the time of returning it keeps updating non-stop as it is returning by URL and not via Session, would like to know how do I return to return via Session?

@EDITION@

Files I am using:

Configuration file (config.php):

define('APP_ID', '42826xxxxxx0624');
define('APP_SECRET', 'fd14bxxxxx04a1fbc');

File where redirects facebook (Login.php):

<?php
    include("functions.php");
    include("config.class.php");
    include("config.php");
    include("modules/Facebook/facebook.php");
    if(@$atual[0]=="facebook"){
        $facebook = new Facebook(array(
                    'appId' => APP_ID,
                    'secret' => APP_SECRET,
                    'cookie'    => TRUE, /* Optional */
                    'oath'      => TRUE  /* Optional */
                    ));

        $access_token   =   $facebook->getAccessToken();
        $user           =   $facebook->getUser();
        if($user){
          try {
            $user_profile = $facebook->api('/me', 'GET');
          } catch (FacebookApiException $e) {
            error_log($e);
            $user = null;
          }
            if (!empty($user_profile)){
                # User info ok? Let's print it (Here we will be adding the login and registering routines)
                $name           = $user_profile['name'];
                $uid            = $user_profile['id'];
                $email          = $user_profile['email'];
                $gender         = $user_profile['gender'];
                $birthday       = $user_profile['birthday'];
                $link           = $user_profile['link'];

                $user = new User();
                if(!$user->checkUserFacebook($uid, $username, $email)){
                    echo '
                        <!-- Modal -->
                        <form action="javascript:func()" name="facebookLogin" id="facebookLogin" method="post" enctype="application/x-www-form-urlencoded" >
                        <div id="myModal" class="modal hide fade" tabindex="-1" data-keyboard="false" data-backdrop="static" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                          <div class="modal-header">
                            <h3 id="myModalLabel">Login com Facebook</h3>
                          </div>
                          <div class="modal-body">
                            <p>
                                <div class="alertLogin"></div>
                                <p class="text-info" id="inputType-name">Nome:  <br>
                                <input class="span6" id="name" type="text" value="'.$name.'" placeholder="Digite seu nome completo" 
                    ';
                    if($name){echo ' disabled ';}
                    echo '
                                ></p>
                                <p class="text-info" id="inputType-cpf">CPF:<br>
                                <input class="span6" id="cpf" name="cpf" type="text" placeholder="Digite seu CPF"></p>
                                <p class="text-info" id="inputType-email">E-mail:<br>
                                <input class="span6" id="email" name="email" type="text" value="'.$email.'" placeholder="Digite seu e-mail" 
                    ';
                                if($email){echo ' disabled ';}
                    echo '
                                ></p>
                                <p class="text-info" id="inputType-phone">Telefone para contato (Somente mostrado caso for ganhador de RIFAS):<br>
                                <input class="span6" id="phone" id="phone" type="text" placeholder="Digite seu Telefone"></p>
                                <input type="hidden" value="'.$uid.'" name="uid" id="uid">
                                <input type="hidden" value="'.$gender.'" name="gender" id="gender">
                                <input type="hidden" value="'.$birthday.'" name="birthday" id="birthday">
                                <input type="hidden" value="'.$link.'" name="link" id="link">
                                <p class="text-info"><input type="checkbox" value="aceitou"> Você aceita nossos termos de uso?</p>
                            </p>
                            </form>
                          </div>
                          <div class="modal-footer">
                            <button class="btn btn-rifao" type="submit">Salvar e logar</button>
                          </div>
                        </div>
                        </form>
                    ';
                }else{
                    $_SESSION["type"]   =   "facebook";
                    $_SESSION["uid"]    =   $uid;
                    header("Location: index.php");
                    exit();
                }
            } else {
                die("There was an error.");
            }
        } else {
            $login_url = $facebook->getLoginUrl(array(
                'scope'=>'email, user_about_me, user_friends, user_birthday, publish_actions, read_stream, user_website',
                'redirect_uri' => 'http://www.rifao.com.br/facebook/'
            ));
            header("Location: " . $login_url);
        }
    }
  • Is it the same API or your PHP? $login_url is the same as http://www.rifao.com.br/facebook/? Maybe this won’t be a problem header("Location: " . $login_url);? The login script is in the URL http://www.rifao.com.br/facebook/? Because if it is, it would explain the loop

  • http://www.rifao.com.br/facebook/ where is script to log in to facebook, it accesses via friendly url.

  • That doesn’t answer my questions, at least not clearly, could you try to be clearer? I’ll ask you again: $login_url is the same as http://www.rifao.com.br/facebook/? The login script is in the URL http://www.rifao.com.br/facebook/?

  • This error is usually because the link that is there in the APP is not the same as the $login_url

  • A simple example of debug :) change the header("Location: " . $login_url); for echo $login_url; and see what it returns, if it returns the same url is because it’s looped (or directing to another that causes the loop)

1 answer

5


1 - Check if your APP, on facebook, is PUBLISHED.

inserir a descrição da imagem aqui

2 - See if permissions are enabled:

inserir a descrição da imagem aqui

3 - Generate a new Secret App and replace the previous one.

4 - Most importantly, see if the url, which is in the api, is the same that contains the fbconnect.php

inserir a descrição da imagem aqui

5 - The basics for getting the data:

<?php

global $user;
$user = $_SESSION['sessao_logado']; 

if(!isset($user)) // Verificando se há login
{

    //Configurações
    $app_id     = "42826xxxxxx0624";
    $app_secret = "fd14bxxxxx04a1fbc";
    $site_url   = "http://www.rifao.com.br/facebook/";

    try{
        include_once "src/facebook.php";
    }catch(Exception $e){
        error_log($e);
    }
    // Criando instância da aplicação
    $facebook = new Facebook(array(
        'appId'     => $app_id,
        'secret'    => $app_secret,
        ));

    // Obtendo o User ID
    $user = $facebook->getUser();

    if($user){
        // Obtendo logout URL
        $logoutUrl = $facebook->getLogoutUrl();
    }else{
        // Obtendo login URL
        $loginUrl = $facebook->getLoginUrl(array(
            'scope'         => 'public_profile, email, user_friends',
            'redirect_uri'  => $site_url,
            ));
    }

    if($user){


        try{

        $user_profile = $facebook->api('/me');
        $name = $user_profile['name'];
        $email = $user_profile['email'];
        $gender = $user_profile['gender'];
        $id = $user_profile['uid_facebook'];

        //AQUI VOCÊ JÁ PODE LOGAR O CLIENTE COM OS DADOS ACIMA
    }

        catch(FacebookApiException $e){
                error_log($e);
                $user = NULL;
        }

    }
}
?>
  • Lollipop, thank you so much for answering! , unfortunately it did not work, so I posted the files used, it would be possible to take a look to see if it is correct? THANK YOU!

  • It worked, @Leonardojoksan?

  • unfortunately no, I don’t know what else to do. Difficult...

  • I’m studying yes, thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.