简体   繁体   中英

facebook redirect url gives blank page

This is the login page script.

<?php
ini_set('error_reporting', E_ALL);
//includes


$id = '[MY ID]';
$secret = '[MY SECRET CODE]';

FacebookSession::setDefaultApplication($id, $secret);
$helper = new FacebookRedirectLoginHelper('[redirect Page]');
$loginUrl = $helper->getLoginUrl();
echo "<a href = " . $loginUrl . ">Login With Facebook</a>";

?>

and this is the redirect page script.

<?php
ini_set('error_reporting', E_ALL);
session_start();
//includes


$helper = new FacebookRedirectLoginHelper();
try {
  $session = $helper->getSessionFromRedirect();
} catch(FacebookRequestException $ex) {
  // When Facebook returns an error
} catch(\Exception $ex) {
  // When validation fails or other local issues
}
if ($session) {
  // Logged in
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
    $graph = $response->getGraphObject(GraphUser::className());
    echo "Hi " . $graph->getName();  


}


?>

when it redirects, it comes to my redirect page and gives a blank page. and the url which it gives is the following :

http://redirectpage?code=[very long code.]

I want this to execute and show me the result.

echo "Hi " . $graph->getName(); 

In your redirect script, make sure the redirect_uri is set to the same as the login page:

$helper = new FacebookRedirectLoginHelper();

should be:

$helper = new FacebookRedirectLoginHelper('[redirect Page]');

The SDK throws an error if the redirect_uri isn't the same as the origin page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM