Anladığım kadarıyla Access Token tam erişim yapamıyorum. Acaba sorunum ne olabilir bakabilir misiniz?
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;
// init app with app id and secret
FacebookSession::setDefaultApplication( 'Test','Test' );
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('http://www.test.com/FBLogin.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?fields=email,first_name,last_name, gender, birthday' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$FBID = $graphObject->getProperty('id'); // To Get Facebook ID
$fbfirst_name = $graphObject->getProperty('first_name');
$fblast_name = $graphObject->getProperty('last_name');
$femail = $graphObject->getProperty('email');
$fbgender = $graphObject->getProperty('gender');
$fbbirthday = $graphObject->getProperty('birthday');
/* ---- Session Variables -----*/
$_SESSION['FBID'] = $FBID;
$_SESSION['EMAIL'] = $femail;
$_SESSION['FIRSTNAME'] = $fbfirst_name;
$_SESSION['LASTNAME'] = $fblast_name;
$_SESSION['GENDER'] = $fbgender;
$_SESSION['BIRTHDAY'] = $fbbirthday;
/* ---- header location after session ----*/
header("Location: index.php");
} else {
$loginUrl = $helper->getLoginUrl();
header("Location: ".$loginUrl);
}
?>