尝试登录时出现 Facebook SDK 错误:未设置网址
我收到以下错误消息
Facebook SDK 返回错误:未设置 URL!
致命错误:未捕获的异常“Facebook\Exceptions\FacebookSDKException”,在 /membri/csslab/sdk/src/Facebook/HttpClients/FacebookCurlHttpClient 中显示消息“No URL set!”.php:83
堆栈跟踪:
0 /membri/csslab/sdk/src/Facebook/FacebookClient.php(216): Facebook\HttpClients\FacebookCurlHttpClient->send('https://graph.f...', 'GET', '', Array, 60)
1 /membri/csslab/sdk/src/Facebook/Authentication/OAuth2Client.php(277): Facebook\FacebookClient->sendRequest(Object(Facebook\FacebookRequest))
2 /membri/csslab/sdk/src/Facebook/Authentication/OAuth2Client.php(226): Facebook\Authentication\OAuth2Client->sendRequestWithClientParams('/oauth/access_t...', Array)
3 /membri/csslab/sdk/src/Facebook/Authentication/OAuth2Client.php(166): Facebook\Authentication\OAuth2Client->requestAnAccessToken(Array)
4 /membri/csslab/sdk/src/Facebook/Helpers/FacebookRedirectLoginHelper.php(255): Facebook\Authentication\OAuth2Client->getAccessTokenFromCode('AQAAf_xMnFr0C7i...', 'http://csslab.a...')
5 /membri/csslab/login-callback.php(30): Facebook\Hel in /membri/csslab/sdk/src/Facebook/HttpClients/FacebookCurlHttpClient.php第83行
尝试使用Facebook凭据登录时。
在当地一切都很好。我已经在Facebook应用程序中正确设置了域名。
我使用的代码是Facebook文档建议的代码:
<?php // login-callback.php
session_start();
function redirect($url, $permanent = false) {
if (headers_sent() === false) {
header('Location: ' . $url, true, ($permanent === true) ? 301 : 302);
}
exit();
}
$path = '';
$uri = 'http://xxxxx.altervista.org';
require_once $path . 'sdk/src/Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => 'xxxxxxxxxxx',
'app_secret' => 'xxxxxxxxxxxxxxxxxxxxxx',
'default_graph_version' => 'v2.5',
]);
$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)) {
// Logged in!
$_SESSION['facebook_access_token'] = (string) $accessToken;
// Now you can redirect to another page and use the
// access token from $_SESSION['facebook_access_token']
redirect($uri . 'survey.php?token='.$_SESSION['facebook_access_token'] , false);
} elseif ($helper->getError()) {
// There was an error (user probably rejected the request)
echo '<p>Error: ' . $helper->getError();
echo '<p>Code: ' . $helper->getErrorCode();
echo '<p>Reason: ' . $helper->getErrorReason();
echo '<p>Description: ' . $helper->getErrorDescription();
exit;
}
?>
更新:
public function send($url, $method, $body, array $headers, $timeOut)
{
$this->openConnection($url, $method, $body, $headers, $timeOut);
$this->sendRequest();
if ($curlErrorCode = $this->facebookCurl->errno()) {
throw new FacebookSDKException($this->facebookCurl->error(), $curlErrorCode);
}
// Separate the raw headers from the raw body
list($rawHeaders, $rawBody) = $this->extractResponseHeadersAndBody();
$this->closeConnection();
return new GraphRawResponse($rawHeaders, $rawBody);
}