I'm trying to implement facebook login on my site, but I'm stuck here. I need user's email. I ask for permissions. If permissions granted everything is fine. If the button "Not Now"(permissions denied) is pressed and he try to login again on the site, the permissions pop-up will no longer appear. How to show the "pop-up" again for users who did not accept the permissions?Thank you!
<?php
if(!isset($_SESSION))
{
session_start();
}
?>
<?php
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;
// start session
// init app with app id and secret
FacebookSession::setDefaultApplication( '12345','12345' );
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper('urlcallback' );
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=name,email' );
$response = $request->execute();
// get response
$graphObject = $response->getGraphObject();
$fbid = $graphObject->getProperty('id'); // To Get Facebook ID
$fbuname = $graphObject->getProperty('username'); // To Get Facebook Username
$fbfullname = $graphObject->getProperty('name'); // To Get Facebook full name
$femail = $graphObject->getProperty('email'); // To Get Facebook email ID
/* ---- Session Variables -----*/
$_SESSION['FBID'] = $fbid;
$_SESSION['USERNAME'] = $fbuname;
$_SESSION['FULLNAME'] = $fbfullname;
$_SESSION['EMAIL'] = $femail;
echo '<pre>' . print_r( $graphObject, 1 ) . '</pre>';
//echo 'email:'.$femail;
} else {
// show login url
echo '<a href="' . $helper->getLoginUrl(array('scope'=>'public_profile,email,user_friends')) . '">Login</a>';
}
?>