Jump to content
techker

Facebook API...

Recommended Posts

Hey guy's im going nuts here trying to figure out how to make this login work...lol!

 

i get :

Response Exception: 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 subdomains of your app to the App Domains field in your app settings.

 

i added every combination URL possible in the section in the facebook dev app settings..

 

www no www / no /  root site members site localhost......

 

and when i refresh i get

SDK Exception: Cross-site request forgery validation failed. Required param "state" missing from persistent data.

 

so i tried for state issue:

 

in login $_SESSION['FBRLH_state']=$_GET['state'];  

	require_once "config.php";

	if (isset($_SESSION['access_token'])) {
		header('Location: index.php');
		exit();
	}
     $_SESSION['FBRLH_state']=$_GET['state'];
	$redirectURL = "https://".$_SERVER['SERVER_NAME']."/Meb/fb-callback.php";
	$permissions = ['email'];
    
	$loginURL = $helper->getLoginUrl($redirectURL, $permissions);
	//echo $redirectURL;
	//die($_SESSION['FBRLH_' . 'state']);
	$accessToken = $helper->getAccessToken()

My callback file:

session_start();
	require_once "config.php";

	try {
		$accessToken = $helper->getAccessToken();
	} catch (\Facebook\Exceptions\FacebookResponseException $e) {
		echo "Response Exception: " . $e->getMessage();
		exit();
	} catch (\Facebook\Exceptions\FacebookSDKException $e) {
		echo "SDK Exception: " . $e->getMessage();
		exit();
	}

	if (!$accessToken) {
		header('Location: login.php');
		exit();
	}

	$oAuth2Client = $FB->getOAuth2Client();
	if (!$accessToken->isLongLived())
		$accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);

	$response = $FB->get("/me?fields=id,user_location, first_name, last_name, email, picture.type(large)", $accessToken);
	$userData = $response->getGraphNode()->asArray();
	$_SESSION['userData'] = $userData;
	$_SESSION['access_token'] = (string) $accessToken;
	header('Location: index.php');
	exit();

config:

	session_start();

	require_once "Facebook/autoload.php";

	$FB = new \Facebook\Facebook([
		'app_id' => 'MYID',
		'app_secret' => 'MYSECRET',
		'default_graph_version' => 'v2.11'
	]);

	$helper = $FB->getRedirectLoginHelper();


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.