Thepeter
Thepeter

Reputation: 127

Facebook SDK v4 it does not redirect

Hello I am working with the sdk v4 facebook and when I login it does not redirect but generates the code ( In low image Link when I log ) Someone can help ?

Image

Code

  <?php
    session_start();

    // Define the root directoy
    define( 'ROOT', dirname( __FILE__ ) . '/' );

    // Autoload the required files
    require_once( ROOT . 'autoload.php' );

    use  Facebook\FacebookSession;
    use  Facebook\FacebookRedirectLoginHelper;
    use  Facebook\FacebookRequest;
    use  Facebook\FacebookSDKException;
    //Dados API
    $app_id = '346646635512123';
    $app_secret = '21h3vj12i312b3hj123';
    $redirect_uri = 'http://localhost:8888/Facebook/';

    // Permissoes 
    $permissions = array('email', 'user_location', 'user_birthday', 'manage_pages', 'publish_actions', 'user_photos');
    FacebookSession::setDefaultApplication($app_id, $app_secret);
    $helper = new FacebookRedirectLoginHelper($redirect_uri);

    try {
      $session = $helper->getSessionFromRedirect(); 
    } catch(Exception $ex) {
      // When validation fails or other local issues
    }
    if (isset( $session)) {
    echo'Estou Ligado'; 
    }
    else
    {
    echo "<a href = " . $helper -> getLoginUrl() . ">Login With Facebook</a>";

    }

?>

Upvotes: 0

Views: 50

Answers (1)

andyrandy
andyrandy

Reputation: 73984

You don´t have any redirection in your code, that is why. You need to click on that login link to get to the authorization screen. I think you misunderstood "FacebookRedirectLoginHelper", it is usefuly AFTER a redirection from the authorization screen.

I would suggest using the JS SDK for authorization though. Much easier to handle, no redirection needed, no PHP needed, ...

Upvotes: 1

Related Questions