Jump to content


Photo

Facebook API...


  • Please log in to reply
No replies to this topic

#1 techker

techker
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 17 May 2018 - 11:34 PM

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();







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users