简体   繁体   中英

Login with facebook error: ERR_TOO_MANY_REDIRECTS

I am trying to login with facebook but i am getting too many redirect error. Please help me how to fix it.

I have tried Browser cookie clear does not work.

<?php
require 'facebook/facebook.php';
require 'config/fbconfig.php';
require 'config/functions.php';

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

$user = $facebook->getUser();

// I think i am not getting user. So i get 0 in user.
if ($user) {

  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } 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)
        $username = $user_profile['name'];
        $uid = $user_profile['id'];
        $email = $user_profile['email'];
        $user = new User();

                $img = file_get_contents('https://graph.facebook.com/'.$user_profile['id'].'/picture?type=large');
                $file = $_SESSION['SITE_IMG_PATH'].'userimage/'.$user_profile['id'].'.jpg';
                file_put_contents($file, $img);
                $userimage=$user_profile['id'].'.jpg';
        $userdata = $user->checkUser($uid, 'facebook', $username,$email,$twitter_otoken,$twitter_otoken_secret,$userimage);

        if(!empty($userdata)){
            session_start();
            $_SESSION['frontuser_info'] = $userdata;

            $Qparam=$fid.''.$sid.''.$tid;

            header("Location: ".$_SESSION['APP_PATH']."".$Qparam);

        }
    } else {
        # For testing purposes, if there was an error, let's kill the script
        die("There was an error.");
    }
} else {

    # There's no active session, let's generate one

    $login_url = $facebook->getLoginUrl(array( 'scope' => 'email'));

    # i think it is always coming here thats error.
    header("Location: " . $login_url);
}

?>

Please see code and help me to fix this redirection error i am always going in else part thats error.

登录 facebook 错误:ERR_TOO_MANY_REDIRECTS

There seems to be some issue with your Facebook Plugin , that's why $user coming as 0. There can be many other reason behind it too. You need to re-check your APP_ID and APP_SECRET as well.

Most importantly, you need to follow below links and update accordingly.

https://github.com/facebook/php-graph-sdk

Or

https://developers.facebook.com/docs/facebook-login/web/login-button/

In my case, i was requesting granted_scopes along with redirecting to provider

then in callback - and as long as there are required scopes in array of declined scopes , i re-requested back but forgot to set granted scopes again, so i ended up in the redirect loop error between application and facebook. Maybe it's your case too.

There is something wrong with Facebook dashboard at the time of this writing.

You could wait for the fix or try skipping dashboard by editing the url by replacing "/dashboard/" with "/settings/basic/".

PS: I had checked browser extensions, cleared browsing history and cookies, disabled Web shields to no avail, only this worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM