I am trying to develop a basic app that uses the Facebook Graph object. I am having a really hard time understanding how to work with basic facebook sessions. Currently, I am able to login to facebook by having the app prompt the user for permission. Once permission is given, the app redirects to the $redirect_url
below. Although, once I get to the actual redirected app.php
script, I am having a hard time accessing the graph object for extended time without getting an error such as:
Facebook\FacebookAuthorizationException' with message 'This authorization code has been used.
Currently the signin.php
code redirects successfully and is capable of accessing graph object within signin script
$app_id = '12334567890';
$app_secret = 'zzzwewe123456789ad8';
$redirect_url = 'http://localhost/www/concept/app.php';
FacebookSession::setDefaultApplication($app_id,$app_secret);
$helper = new FacebookRedirectLoginHelper($redirect_url);
$sess = $helper->getSessionFromRedirect();
if(isset($sess)){
$access_token = $sess->getToken();
$session = new FacebookSession($access_token);
$request = new FacebookRequest($sess, 'GET', '/me');
$response = $request->execute();
$graph = $response->getGraphObject(GraphUser::classname());
$name = $graph->getName();
echo $name;
}else{
echo '<a href="'.$helper->getLoginUrl().'"> Login with facebook</a>';
}
Currently the app.php
is where the above script redirects to, this is where I am unable to access the graph object without getting the error: Facebook\FacebookAuthorizationException' with message 'This authorization code has been used.
All I am trying to do at this point, is just output the name of the user on the redirect page, using the graph object and I need to be able to refresh the page without getting the above mentioned error.
I truly appreciate any advice
Aucun commentaire:
Enregistrer un commentaire