0
我試圖在我的網站上實現Facebook登錄,但我被卡在這裏。 我需要用戶的電子郵件。 我請求權限。如果權限授予一切都很好。 如果按下「不立即」按鈕(權限被拒絕)並且他嘗試在網站上再次登錄,彈出的權限將不再顯示。 如何爲不接受權限的用戶再次顯示「彈出窗口」?謝謝!Facebook登錄權限被拒絕
<?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>';
}
?>