這是我的工作流程。用戶轉到index.php並重定向到Facebook登錄。登錄後,他們被重定向到post.php,我有效的$session
。我能夠在本地工作,但只要我將其上傳到我的服務器,$session
變量就會返回NULL
。
這是我的代碼post.php
。
session_start();
require_once("../assets/resources/constants.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;
// init app with app id (APPID) and secret (SECRET)
FacebookSession::setDefaultApplication(FACEBOOK_APP_ID,FACEBOOK_APP_SECRET);
// login helper with redirect_uri
$helper = new FacebookRedirectLoginHelper(BASE_URL."/facebook/post.php");
try {
$session = $helper->getSessionFromRedirect();
if (isset($session)) $_SESSION['token'] = $session->getToken();
} catch(FacebookRequestException $ex) {
// When Facebook returns an error
} catch(Exception $ex) {
unset($session);
echo $ex->getMessage();
}
var_dump($session);
exit();
我做了一些挖掘,並能夠得到這個錯誤拋出。
object(Facebook\FacebookAuthorizationException)#10 (10) { ["statusCode":"Facebook\FacebookRequestException":private]=> int(400) ["rawResponse":"Facebook\FacebookRequestException":private]=> string(190) "{"error":{"message":"Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request","type":"OAuthException","code":100}}" ["responseData":"Facebook\FacebookRequestException":private]=> array(1) { ["error"]=> array(3) { ["message"]=> string(131) "Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request" ["type"]=> string(14) "OAuthException" ["code"]=> int(100) } } ["message":protected]=> string(131) "Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(100) ["file":protected]=> string(71) "/var/www/html/facebook/assets/sdk/Facebook/FacebookRequestException.php" ["line":protected]=> int(104) ["trace":"Exception":private]=> array(3) { [0]=> array(6) { ["file"]=> string(62) "/var/www/html/facebook/assets/sdk/Facebook/FacebookRequest.php" ["line"]=> int(268) ["function"]=> string(6) "create" ["class"]=> string(33) "Facebook\FacebookRequestException" ["type"]=> string(2) "::" ["args"]=> array(3) { [0]=> string(190) "{"error":{"message":"Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request","type":"OAuthException","code":100}}" [1]=> object(stdClass)#9 (3) { ["message"]=> string(131) "Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request" ["type"]=> string(14) "OAuthException" ["code"]=> int(100) } [2]=> int(400) } } [1]=> array(6) { ["file"]=> string(74) "/var/www/html/facebook/assets/sdk/Facebook/FacebookRedirectLoginHelper.php" ["line"]=> int(175) ["function"]=> string(7) "execute" ["class"]=> string(24) "Facebook\FacebookRequest" ["type"]=> string(2) "->" ["args"]=> array(0) { } } [2]=> array(6) { ["file"]=> string(31) "/var/www/html/facebook/post.php" ["line"]=> int(32) ["function"]=> string(22) "getSessionFromRedirect" ["class"]=> string(36) "Facebook\FacebookRedirectLoginHelper" ["type"]=> string(2) "->" ["args"]=> array(0) { } } } ["previous":"Exception":private]=> NULL }
生產服務器上安裝了哪個版本的PHP? – Artamiel
@Andariel生產服務器有5.4.39 – Jako