php 尝试登录时出现Facebook SDK错误:未设置URL

3j86kqsm  于 2023-01-16  发布在  PHP
关注(0)|答案(3)|浏览(112)

我收到以下错误消息
Facebook SDK返回错误:没有设置URL!
致命错误:/membri/cslab/sdk/src/Facebook/HttpClients/Facebook服务器/Facebook服务器/Facebook服务器发生异常'Facebook\Exceptions\Facebook服务器异常'并显示消息'没有设置URL!'
堆栈跟踪:
0/membri/cslab/软件开发工具包/源代码/Facebook/Facebook客户端. php(216):Facebook\HttpClient\Facebook curl HttpClient-〉发送("https://graph.f ...","获取",",数组,60)
1/成员/软件开发包/源代码/Facebook/身份验证/OAuth2Client.php(277):Facebook\Facebook客户端-〉发送请求(对象(Facebook\Facebook请求))
2/登录/服务器/软件开发包/源代码/Facebook/身份验证/OAuth2Client.php(226):Facebook\身份验证\OAuth2Client-〉发送带有客户端参数的请求('/oauth/access_t ...',数组)
3/成员/cslab/软件开发工具/源代码/Facebook/身份验证/OAuth2Client.php(166):Facebook\身份验证\OAuth2客户端-〉请求访问令牌(数组)
4/成员/登录/软件开发包/源代码/Facebook/Helpers/Facebook重定向登录助手. php(255):Facebook\身份验证\OAuth2客户端-〉从代码获取访问令牌('AQAAf_xMnFr0C7i ...',' http://csslab.a ...')
5/membri/csslab/登录回叫. php(30):Facebook的\在/membri/csslab/sdk/src/Facebook的/HttpClient/Facebook的 curl HttpClient. 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);
}
6l7fqoea

6l7fqoea1#

OAuth帮助管理您必须验证的访问令牌

// Logged in
echo '<h3>Access Token</h3>';
var_dump($accessToken->getValue());

// 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);
echo '<h3>Metadata</h3>';
var_dump($tokenMetadata);

// Validation (these will throw FacebookSDKException's when they fail)
$tokenMetadata->validateAppId({app-id}); // Replace {app-id} with your app id
// 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>\n\n";
    exit;
  }

  echo '<h3>Long-lived</h3>';
  var_dump($accessToken->getValue());
}

$_SESSION['fb_access_token'] = (string) $accessToken;

// User is logged in with a long-lived access token.
// You can redirect them to a members-only page.
//header('Location: https://example.com/members.php');
dgtucam1

dgtucam12#

我不知道这是否有帮助,但你可以使用一个包来处理社会登录(fb,twitter,google,...)你可能想看看这个PHP联盟包,并使用他们的库,而不是使用Facebook的SDK。
https://github.com/thephpleague/oauth2-client
有时候当你真的陷入困境时,从不同的Angular 尝试会有所帮助。

o3imoua4

o3imoua43#

检查你的回调网址或开放认证网址在facebook开发者面板。并确保你把https://在回调网址的开头。这是真的老错误facebook...也许这可以帮助...

相关问题