Search code examples
phpfacebook-php-sdk

fb login helper error


I did everything perfect but when i click on the link of the login helper it redirects me to the facebook page and gives this error:

Can't load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and sub-domains of your app to the App Domains field in your app settings.

Any suggestions?

my facebook developer app settings

 <?php
session_start();
// added in v4.0.0
require_once 'autoload.php';

use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;

// start session

// init app with app id and secret
FacebookSession::setDefaultApplication( '367245673760849','my secret goes here' );

// login helper with redirect_uri

    $helper = new FacebookRedirectLoginHelper('http://saturnproduction.com/test.php' );

try {
  $session = $helper->getSessionFromRedirect();
} catch( FacebookRequestException $ex ) {
  // When Facebook returns an error
} catch( Exception $ex ) {
  // When validation fails or other local issues
}

// see if we have a session
if ( isset( $session ) ) {
  // graph api request for user data
  $request = new FacebookRequest( $session, 'GET', '/me' );
  $response = $request->execute();
  // get response
  $graphObject = $response->getGraphObject();

        $fbid = $graphObject->getProperty('id');              // To Get Facebook ID
        $fbuname = $graphObject->getProperty('username');  // To Get Facebook Username
        $fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
        $femail = $graphObject->getProperty('email');    // To Get Facebook email ID
    /* ---- Session Variables -----*/
        $_SESSION['FBID'] = $fbid;           
        $_SESSION['USERNAME'] = $fbuname;
        $_SESSION['FULLNAME'] = $fbfullname;
        $_SESSION['EMAIL'] =  $femail;
    echo '<pre>' . print_r( $graphObject, 1 ) . '</pre>';
} else {
  // show login url
  echo '<a href="' . $helper->getLoginUrl() . '">Login</a>';
}

?>

Solution

  • You have to input all the URLs in Valid OAuth Redirect URIs.

    API Documentation : https://developers.facebook.com/docs/facebook-login/security/#surfacearea

    Go to App Dashboard, then under Products /Facebook Login /Setting

    Link : https://developers.facebook.com/apps/App_ID/fb-login/settings/

    Replace it with your App_ID = 367245673760849 According to the code sniped mentioned above URL should be http://saturnproduction.com/test.php

    Refer Screenshot if any doubts: enter image description here