Facebook Graph returned an error: failed to load URL

login.php

if(!session_id()) {
    session_start();
}

require_once __DIR__ . "/vendor/autoload.php";

$facebook_appId = "123";
$facebook_appSecret = "123";

$fb = new Facebook\Facebook([
  "app_id" => $facebook_appId,
  "app_secret" => $facebook_appSecret,
  "default_graph_version" => "v2.11",
]);

$helper = $fb->getRedirectLoginHelper();

$permissions = ["email"]; // Optional permissions
$loginUrl = $helper->getLoginUrl("http://www.123.com/login-callback.php", $permissions);

echo "<a href="" . htmlspecialchars($loginUrl) . "">Login via Facebook!</a>";

login-callback.php

if(!session_id()) {
    session_start();
}

require_once __DIR__ . "/vendor/autoload.php";

$facebook_appId = "123";
$facebook_appSecret = "123";

$fb = new \Facebook\Facebook([
    "app_id" => $facebook_appId,
    "app_secret" => $facebook_appSecret,
    "default_graph_version" => "v2.11",
]);

// Use one of the helper classes to get a Facebook\Authentication\AccessToken entity.
//   $helper = $fb->getRedirectLoginHelper();
//   $helper = $fb->getJavaScriptHelper();
//   $helper = $fb->getCanvasHelper();
//   $helper = $fb->getPageTabHelper();

try {
  // Get the \Facebook\GraphNodes\GraphUser object for the current user.
  // If you provided a "default_access_token", the "{access-token}" is optional.

  $helper = $fb->getRedirectLoginHelper();  
  $accessToken = $helper->getAccessToken();
  $response = $fb->get("/me?fields=id,name", $accessToken );
  // $response = $fb->get("/me", $accessToken );

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

$me = $response->getGraphUser();
echo "Logged in as " . $me->getName();

above is the code of my two php files. When I click on the link output from login.php and jump to the second php, I report an error
[Graph returned an error: cannot load URL: the domain name of this URL does not contain the domain name of the application. In order to be able to load URL, please add all application domains and subdomains in the Application Domain name field of the application settings. ]

I have added this domain name to the facebook developer platform, and I have checked url carefully and found no difference. I don"t know why I still reported this error. Please check it for me if you have asked a friend who has logged in to facebook to take a look at it for me.

Mar.09,2021

your domain name should not be added to Valid OAuth Redirect URIs . It is estimated that you only added it to the setting .

clipboard.png


facebookphp sdk5.6.25.6.1



clipboard.png

Graph returned an error: cannot load URL: the domain name of this URL does not contain the domain name of the application. In order to be able to load URL, please add all application domains and subdomains in the Application Domain name field of the application settings. But the upgrade to 5.62 version is still the same error, what is your QQ number?

Menu