登录facebook错误:ERR_TOO_MANY_REDIRECTS

时间:2017-11-17 05:27:21

标签: php facebook facebook-graph-api facebook-php-sdk facebook-login

我正在尝试使用facebook登录,但我收到了太多的重定向错误。请帮我解决一下。

我尝试过浏览器Cookie清除不起作用。

<?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);
}

?>

请查看代码并帮助我修复此重定向错误,我总是会在其他部分发生错误。

Login with facebook error: ERR_TOO_MANY_REDIRECTS

3 个答案:

答案 0 :(得分:0)

您的Facebook Plugin似乎存在一些问题,这就是$user为0的原因。其背后还有许多其他原因。您还需要重新检查APP_IDAPP_SECRET

最重要的是,您需要按照以下链接进行相应更新。

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

或者

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

答案 1 :(得分:0)

在我的情况下,我正在请求 granted_scopes 以及重定向到提供商

然后在回调中 - 只要拒绝范围的数组中有所需的范围,我重新请求,但忘记设置授予的范围< / em>再次,所以我最终在应用程序和Facebook之间的重定向循环错误。也许这也是你的情况。

答案 2 :(得分:0)

在撰写本文时,Facebook仪表板有问题。

您可以等待修复,也可以尝试通过编辑网址来跳过仪表板,方法是将“ / dashboard /”替换为“ / settings / basic /”。

PS:我检查了浏览器扩展,清除了浏览历史记录和cookie,禁用了Web屏蔽,但无济于事,