Facebook 登录 PHP:URL 已阻止:此重定向失败,因为重定向 URI 未在应用程序的客户端 OAuth 设置中列入白名单

Facebook login PHP: URL Blocked: This redirect failed because the redirect URI is not whitelisted in the app’s Client OAuth Settings

我正在使用 Parse Server 在我的网站上使用 Facebook 登录,当然,我有 Facebook PHP SDK 的所有代码来处理登录,直到几天前它都运行良好。 ' 这是我在尝试登录时遇到的错误:

URL Blocked: This redirect failed because the redirect URI is not whitelisted in the app’s Client OAuth Settings. Make sure Client and Web OAuth Login are on and add all your app domains as Valid OAuth Redirect URIs.

我的 Facebook 登录设置:

这是我的 fb-callback.php 脚本:

<?php
require_once 'fb-autoload.php';
include 'Configs.php';
// include 'fbconfig.php';

$fb = new Facebook\Facebook([
  'app_id' => $_GLOBALS["FACEBOOK_APP_ID"],
  'app_secret' => $_GLOBALS["FACEBOOK_APP_SECRET"],
  'default_graph_version' => 'v2.3',
  ]);

$helper = $fb->getRedirectLoginHelper();

if (isset($_GET['state'])) {
    $helper->getPersistentDataHandler()->set('state', $_GET['state']);
}


try {
  $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)) {
  if ($helper->getError()) {
    header('HTTP/1.0 401 Unauthorized');
    echo "Error: " . $helper->getError() . "\n";
    echo "Error Code: " . $helper->getErrorCode() . "\n";
    echo "Error Reason: " . $helper->getErrorReason() . "\n";
    echo "Error Description: " . $helper->getErrorDescription() . "\n";
  } else {
    header('HTTP/1.0 400 Bad Request');
    echo 'Bad request';
  }
  exit;
}

// Logged in
// echo '<h3>Access Token:</h3>';
// var_dump($accessToken->getValue());

// The OAuth 2.0 client handler helps us manage access tokens
$oAuth2Client = $fb->getOAuth2Client();

// Get the access token metadata from /debug_token
$tokenMetadata = $oAuth2Client->debugToken($accessToken);
// echo '<h3>METADATA:</h3>';
// var_dump($tokenMetadata);


// Validation (these will throw FacebookSDKException's when they fail)
$tokenMetadata->validateAppId($_GLOBALS["FACEBOOK_APP_ID"]); // Replace {app-id} with your app id
// If you know the user ID this access token belongs to, you can validate it here
//$tokenMetadata->validateUserId('123');
$tokenMetadata->validateExpiration();

if (! $accessToken->isLongLived()) {
  // Exchanges a short-lived access token for a long-lived one
  try {
    $accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
  } catch (Facebook\Exceptions\FacebookSDKException $e) {
    echo "<p>Error getting long-lived access token: " . $helper->getMessage() . "</p>\n\n";
    exit;
  }

  //echo '<h3>Long-lived</h3>';
  //var_dump($accessToken->getValue());
}

$_SESSION['fb_access_token'] = (string) $accessToken;

// User is logged in with a long-lived access token.
// You can redirect them to a members-only page.
// header('Location: login.php');

// CHECK IF SESSION IS OK, GET GRAPH OBJECT AND GO BACK TO login.php
if (isset($_SESSION)) {

  $response = $fb->get('/me?fields=id,name', $accessToken);
  $node = $response->getGraphNode();

  // Get ID, Name and Email of Facebook user
  $fbid = $node->getField('id');         // To Get Facebook ID
  $fbfullname = $node->getField('name'); // To Get Facebook full name
  $femail = $node->getField('email');    // To Get Facebook email ID
  // $token = $session->getToken(); // Get Access Token
  $token = $_SESSION['fb_access_token'];


  // ---- Session Variables -----
  $_SESSION['FBID'] = $fbid;
  $_SESSION['FULLNAME'] = $fbfullname;
  $_SESSION['EMAIL'] =  $femail;
  $_SESSION['TOKEN'] = $token;


// ---- GO TO fb-login.php ----
header("Location: fb-login-confirm.php");

} else {
    $loginUrl = $helper->getLoginUrl();
    header("Location: ".$loginUrl);
}
?>

我不知道我是否还需要edit/add其他东西,正如我上面所说,我的 FB 登录在几天前一直运行顺利。

问题很简单,我的 URL 在 Valid OAuth redirect URIs 字段中缺少 www

 https://www.example.com/woopy/fb-callback.php