我是这个领域的新手,对于我犯的任何错误感到抱歉
我创建了一个使用Facebook登录facebook php sdk的网站。 我在我的localhost上测试过,它工作正常,但是当我上传到互联网上的真实服务器时。它捕获了facebook sdk异常,但异常返回null。 我不知道如何检查它,因为在我的wamp服务器上一切正常。
这是我的登录代码。
require_once __DIR__ . '/Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => '?',
'app_secret' => '?',
'default_graph_version' => 'v2.4',
]);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['email','public_profile','user_likes']; // Optional permissions
$loginUrl = $helper->getLoginUrl('http://example.com/logincallback.php', $permissions);
echo '<a href="' . htmlspecialchars($loginUrl) . '"><img src="../images/system/fbround.png" width="50" height="50" /></a>';
这是我的重定向页面。
include("config.php");
require_once __DIR__. '/pages/Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => '?',
'app_secret' => '?',
'default_graph_version' => 'v2.4',
]);
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
}
catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (! isset($accessToken)) {
if ($helper->getError()) {
header('HTTP/1.0 401 Unauthorized');
echo "Error: " . $helper->getError() . "\n";
echo "Error Code: " . $helper->getErrorCode() . "\n";
echo "Error Reason: " . $helper->getErrorReason() . "\n";
echo "Error Description: " . $helper->getErrorDescription() . "\n";
} else {
header('HTTP/1.0 400 Bad Request');
echo 'Bad request';
}
exit;
}
// The OAuth 2.0 client handler helps us manage access tokens
$oAuth2Client = $fb->getOAuth2Client();
// Get the access token metadata from /debug_token
$tokenMetadata = $oAuth2Client->debugToken($accessToken);
$response = $fb->get('/me?fields=id,name,email', $accessToken->getValue());
$user = $response->getGraphUser();
$_SESSION['user_fbid']=$user['id'];
$_SESSION['user_email']=$user['email'];
$_SESSION['user_fullname']=$user['name'];
$_SESSION['accesstoken']=(string) $accessToken;
$_SESSION['facebooklogin']='1';
// Validation (these will throw FacebookSDKException's when they fail)
$tokenMetadata->validateAppId('1501129246877759');
// If you know the user ID this access token belongs to, you can validate it here
// $tokenMetadata->validateUserId('123');
$tokenMetadata->validateExpiration();
if (! $accessToken->isLongLived()) {
// Exchanges a short-lived access token for a long-lived one
try {
$accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
} catch (Facebook\Exceptions\FacebookSDKException $e) {
echo "<p>Error getting long-lived access token: " . $helper->getMessage() . "</p>";
exit;
}
echo '<h3>Long-lived</h3>';
var_dump($accessToken->getValue());
}
header('Location: http://example.com');
我在facebook app上获得了此代码。 我在我的在线服务器上启用了php_curl扩展和php_mbstring扩展 但它始终返回异常错误和描述。
这是错误:
Facebook SDK returned an error:
我现在不知道为什么它不能在我的在线服务器上运行。但它在我的wamp服务器上完美运行。
这是捕获的例外
object(Facebook\Exceptions\FacebookSDKException)#14 (7) { ["message":protected]=> string(0) "" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(7) ["file":protected]=> string(74) "/home/www/yeaksa.com/pages/Facebook/HttpClients/FacebookCurlHttpClient.php" ["line":protected]=> int(83) ["trace":"Exception":private]=> array(6) { [0]=> array(6) { ["file"]=> string(54) "/home/www/yeaksa.com/pages/Facebook/FacebookClient.php" ["line"]=> int(216) ["function"]=> string(4) "send" ["class"]=> string(43) "Facebook\HttpClients\FacebookCurlHttpClient" ["type"]=> string(2) "->" ["args"]=> array(5) { [0]=> string(1029) "https://graph.facebook.com/v2.4/oauth/access_token?code=AQA1pHyXLTD8BIkpNG8gd60h0kI2I0uJpKS5KOtwSZPU0Ak1H_a0_cXaORNasnKmXRHTSqBngUGepiTEwmPMvHsbGRku53SXI6t0oPXIjMdR8JAwPyuozltmaKfg_UZ6zeCVJrnPDsoBvFoznY4tQqSUQw-81fbvUui9kSVhJQhtRIlUrNE4vhd23EPNv0454enY4H3K2waGFtcg4qolyAGLOXqn6szOJj2HHZkUkqlvqaBchkvu55154aX5sp35cENjLgWcTFgRiGSHzcH20nQX_EOoHq5D5q6VCsT1OAFSq0DCIk3_nxDFvP1vl4T1kq99SegDVe-OPhBIAOLyMcxu&redirect_uri=http%3A%2F%2Fyeaksa.com%2Flogincallback.php%3Fcode%3DAQA1pHyXLTD8BIkpNG8gd60h0kI2I0uJpKS5KOtwSZPU0Ak1H_a0_cXaORNasnKmXRHTSqBngUGepiTEwmPMvHsbGRku53SXI6t0oPXIjMdR8JAwPyuozltmaKfg_UZ6zeCVJrnPDsoBvFoznY4tQqSUQw-81fbvUui9kSVhJQhtRIlUrNE4vhd23EPNv0454enY4H3K2waGFtcg4qolyAGLOXqn6szOJj2HHZkUkqlvqaBchkvu55154aX5sp35cENjLgWcTFgRiGSHzcH20nQX_EOoHq5D5q6VCsT1OAFSq0DCIk3_nxDFvP1vl4T1kq99SegDVe-OPhBIAOLyMcxu&client_id=171845566490390&client_secret=444cd426e0262bcf9c5c0c8fe34b4e7a&access_token=171845566490390%7C444cd426e0262bcf9c5c0c8fe34b4e7a&appsecret_proof=fcac56612f51e2c41a4b07c2f7746035c7dfe29e2542225b8a804ae33845aa62" [1]=> string(3) "GET" [2]=> string(0) "" [3]=> array(3) { ["Content-Type"]=> string(33) "application/x-www-form-urlencoded" ["User-Agent"]=> string(12) "fb-php-5.0.0" ["Accept-Encoding"]=> string(1) "*" } [4]=> int(60) } } [1]=> array(6) { ["file"]=> string(67) "/home/www/yeaksa.com/pages/Facebook/Authentication/OAuth2Client.php" ["line"]=> int(277) ["function"]=> string(11) "sendRequest" ["class"]=> string(23) "Facebook\FacebookClient" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> object(Facebook\FacebookRequest)#13 (9) { ["app":protected]=> object(Facebook\FacebookApp)#3 (2) { ["id":protected]=> string(15) "171845566490390" ["secret":protected]=> string(32) "444cd426e0262bcf9c5c0c8fe34b4e7a" } ["accessToken":protected]=> string(48) "171845566490390|444cd426e0262bcf9c5c0c8fe34b4e7a" ["method":protected]=> string(3) "GET" ["endpoint":protected]=> string(19) "/oauth/access_token" ["headers":protected]=> array(1) { ["Content-Type"]=> string(33) "application/x-www-form-urlencoded" } ["params":protected]=> array(4) { ["code"]=> string(344) "AQA1pHyXLTD8BIkpNG8gd60h0kI2I0uJpKS5KOtwSZPU0Ak1H_a0_cXaORNasnKmXRHTSqBngUGepiTEwmPMvHsbGRku53SXI6t0oPXIjMdR8JAwPyuozltmaKfg_UZ6zeCVJrnPDsoBvFoznY4tQqSUQw-81fbvUui9kSVhJQhtRIlUrNE4vhd23EPNv0454enY4H3K2waGFtcg4qolyAGLOXqn6szOJj2HHZkUkqlvqaBchkvu55154aX5sp35cENjLgWcTFgRiGSHzcH20nQX_EOoHq5D5q6VCsT1OAFSq0DCIk3_nxDFvP1vl4T1kq99SegDVe-OPhBIAOLyMcxu" ["redirect_uri"]=> string(385) "http://yeaksa.com/logincallback.php?code=AQA1pHyXLTD8BIkpNG8gd60h0kI2I0uJpKS5KOtwSZPU0Ak1H_a0_cXaORNasnKmXRHTSqBngUGepiTEwmPMvHsbGRku53SXI6t0oPXIjMdR8JAwPyuozltmaKfg_UZ6zeCVJrnPDsoBvFoznY4tQqSUQw-81fbvUui9kSVhJQhtRIlUrNE4vhd23EPNv0454enY4H3K2waGFtcg4qolyAGLOXqn6szOJj2HHZkUkqlvqaBchkvu55154aX5sp35cENjLgWcTFgRiGSHzcH20nQX_EOoHq5D5q6VCsT1OAFSq0DCIk3_nxDFvP1vl4T1kq99SegDVe-OPhBIAOLyMcxu" ["client_id"]=> string(15) "171845566490390" ["client_secret"]=> string(32) "444cd426e0262bcf9c5c0c8fe34b4e7a" } ["files":protected]=> array(0) { } ["eTag":protected]=> NULL ["graphVersion":protected]=> string(4) "v2.4" } } } [2]=> array(6) { ["file"]=> string(67) "/home/www/yeaksa.com/pages/Facebook/Authentication/OAuth2Client.php" ["line"]=> int(226) ["function"]=> string(27) "sendRequestWithClientParams" ["class"]=> string(36) "Facebook\Authentication\OAuth2Client" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(19) "/oauth/access_token" [1]=> array(2) { ["code"]=> string(344) "AQA1pHyXLTD8BIkpNG8gd60h0kI2I0uJpKS5KOtwSZPU0Ak1H_a0_cXaORNasnKmXRHTSqBngUGepiTEwmPMvHsbGRku53SXI6t0oPXIjMdR8JAwPyuozltmaKfg_UZ6zeCVJrnPDsoBvFoznY4tQqSUQw-81fbvUui9kSVhJQhtRIlUrNE4vhd23EPNv0454enY4H3K2waGFtcg4qolyAGLOXqn6szOJj2HHZkUkqlvqaBchkvu55154aX5sp35cENjLgWcTFgRiGSHzcH20nQX_EOoHq5D5q6VCsT1OAFSq0DCIk3_nxDFvP1vl4T1kq99SegDVe-OPhBIAOLyMcxu" ["redirect_uri"]=> string(385) "http://yeaksa.com/logincallback.php?code=AQA1pHyXLTD8BIkpNG8gd60h0kI2I0uJpKS5KOtwSZPU0Ak1H_a0_cXaORNasnKmXRHTSqBngUGepiTEwmPMvHsbGRku53SXI6t0oPXIjMdR8JAwPyuozltmaKfg_UZ6zeCVJrnPDsoBvFoznY4tQqSUQw-81fbvUui9kSVhJQhtRIlUrNE4vhd23EPNv0454enY4H3K2waGFtcg4qolyAGLOXqn6szOJj2HHZkUkqlvqaBchkvu55154aX5sp35cENjLgWcTFgRiGSHzcH20nQX_EOoHq5D5q6VCsT1OAFSq0DCIk3_nxDFvP1vl4T1kq99SegDVe-OPhBIAOLyMcxu" } } } [3]=> array(6) { ["file"]=> string(67) "/home/www/yeaksa.com/pages/Facebook/Authentication/OAuth2Client.php" ["line"]=> int(166) ["function"]=> string(20) "requestAnAccessToken" ["class"]=> string(36) "Facebook\Authentication\OAuth2Client" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> array(2) { ["code"]=> string(344) "AQA1pHyXLTD8BIkpNG8gd60h0kI2I0uJpKS5KOtwSZPU0Ak1H_a0_cXaORNasnKmXRHTSqBngUGepiTEwmPMvHsbGRku53SXI6t0oPXIjMdR8JAwPyuozltmaKfg_UZ6zeCVJrnPDsoBvFoznY4tQqSUQw-81fbvUui9kSVhJQhtRIlUrNE4vhd23EPNv0454enY4H3K2waGFtcg4qolyAGLOXqn6szOJj2HHZkUkqlvqaBchkvu55154aX5sp35cENjLgWcTFgRiGSHzcH20nQX_EOoHq5D5q6VCsT1OAFSq0DCIk3_nxDFvP1vl4T1kq99SegDVe-OPhBIAOLyMcxu" ["redirect_uri"]=> string(385) "http://yeaksa.com/logincallback.php?code=AQA1pHyXLTD8BIkpNG8gd60h0kI2I0uJpKS5KOtwSZPU0Ak1H_a0_cXaORNasnKmXRHTSqBngUGepiTEwmPMvHsbGRku53SXI6t0oPXIjMdR8JAwPyuozltmaKfg_UZ6zeCVJrnPDsoBvFoznY4tQqSUQw-81fbvUui9kSVhJQhtRIlUrNE4vhd23EPNv0454enY4H3K2waGFtcg4qolyAGLOXqn6szOJj2HHZkUkqlvqaBchkvu55154aX5sp35cENjLgWcTFgRiGSHzcH20nQX_EOoHq5D5q6VCsT1OAFSq0DCIk3_nxDFvP1vl4T1kq99SegDVe-OPhBIAOLyMcxu" } } } [4]=> array(6) { ["file"]=> string(75) "/home/www/yeaksa.com/pages/Facebook/Helpers/FacebookRedirectLoginHelper.php" ["line"]=> int(255) ["function"]=> string(22) "getAccessTokenFromCode" ["class"]=> string(36) "Facebook\Authentication\OAuth2Client" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(344) "AQA1pHyXLTD8BIkpNG8gd60h0kI2I0uJpKS5KOtwSZPU0Ak1H_a0_cXaORNasnKmXRHTSqBngUGepiTEwmPMvHsbGRku53SXI6t0oPXIjMdR8JAwPyuozltmaKfg_UZ6zeCVJrnPDsoBvFoznY4tQqSUQw-81fbvUui9kSVhJQhtRIlUrNE4vhd23EPNv0454enY4H3K2waGFtcg4qolyAGLOXqn6szOJj2HHZkUkqlvqaBchkvu55154aX5sp35cENjLgWcTFgRiGSHzcH20nQX_EOoHq5D5q6VCsT1OAFSq0DCIk3_nxDFvP1vl4T1kq99SegDVe-OPhBIAOLyMcxu" [1]=> string(385) "http://yeaksa.com/logincallback.php?code=AQA1pHyXLTD8BIkpNG8gd60h0kI2I0uJpKS5KOtwSZPU0Ak1H_a0_cXaORNasnKmXRHTSqBngUGepiTEwmPMvHsbGRku53SXI6t0oPXIjMdR8JAwPyuozltmaKfg_UZ6zeCVJrnPDsoBvFoznY4tQqSUQw-81fbvUui9kSVhJQhtRIlUrNE4vhd23EPNv0454enY4H3K2waGFtcg4qolyAGLOXqn6szOJj2HHZkUkqlvqaBchkvu55154aX5sp35cENjLgWcTFgRiGSHzcH20nQX_EOoHq5D5q6VCsT1OAFSq0DCIk3_nxDFvP1vl4T1kq99SegDVe-OPhBIAOLyMcxu" } } [5]=> array(6) { ["file"]=> string(38) "/home/www/yeaksa.com/logincallback.php" ["line"]=> int(15) ["function"]=> string(14) "getAccessToken" ["class"]=> string(44) "Facebook\Helpers\FacebookRedirectLoginHelper" ["type"]=> string(2) "->" ["args"]=> array(0) { } } } ["previous":"Exception":private]=> NULL }
请帮帮我。提前谢谢。