我被困住了... 一切看起来都正确,但是不起作用。在我来自Facebook开发人员的应用程序中使用了调试访问令牌进行了尝试,它工作得很好,因此与代码的恢复无关。
index.php
<?php
session_start();
/******Improting Facebook API Files**************/
require_once 'src/Facebook/autoload.php';
require_once 'credentials.php';
/******Facebook API Connection With My APP**************/
$fb = new Facebook\Facebook([
'app_id' => $appid,
'app_secret' => $appsecret,
'default_graph_version' => 'v2.3'
]);
/******Initializing The Login**************/
$helper = $fb->getRedirectLoginHelper();
$permissions = ['email', 'public_profile']; // optional
#echo '<script type="text/javascript">alert("'.$incommingurl.'");</script>';
#echo '<script type="text/javascript">alert("'.$permissions.'");</script>';
#var_dump($permissions);
#var_dump($helper);
$loginUrl = $helper->getLoginUrl($incommingurl, $permissions);
/******Printing The Login URL**************/
echo'<a href="' . $loginUrl . '" class="facebookLoginButton" title="Login With Facebook">Sign in with Facebook</a>';
?>
token.php
<?php
session_start();
/******Improting Facebook API Files**************/
require_once 'src/Facebook/autoload.php';
require_once 'credentials.php';
/******Facebook API Connection With My APP**************/
$fb = new Facebook\Facebook([
'app_id' => $appid,
'app_secret' => $appsecret,
'default_graph_version' => 'v2.3'
]);
$helper = $fb->getRedirectLoginHelper();
/******Getting Token From Facebook**************/
var_dump($helper);
try {
echo '<script type="text/javascript"> alert("1235")</script>';
$accessToken = $helper->getAccessToken();
var_dump($accessToken);
} 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;
}
/******Storing Token In Sessions For Further Use**************/
if (isset($accessToken)) {
$_SESSION['token'] = (string) $accessToken;
echo $_SESSION['token'];
header('location: collectUserData.php');
}
else{
//echo "err";
header('location: index.php');
}
?>
使用有效令牌设置$ accesstoken,代码可以正常工作,因此无法获取访问令牌。我可以转储$ helper,结果是:
object(Facebook\Helpers\FacebookRedirectLoginHelper)#7 (4) { ["oAuth2Client":protected]=> object(Facebook\Authentication\OAuth2Client)#8 (4) { ["app":protected]=> object(Facebook\FacebookApp)#3 (2) { ["id":protected]=> string(15) "xxxxxxxxxxxx" ["secret":protected]=> string(32) "xxxxxxxxxxxxxxxxxx" } ["client":protected]=> object(Facebook\FacebookClient)#4 (2) { ["enableBetaMode":protected]=> bool(false) ["httpClientHandler":protected]=> object(Facebook\HttpClients\FacebookCurlHttpClient)#5 (4) { ["curlErrorMessage":protected]=> string(0) "" ["curlErrorCode":protected]=> int(0) ["rawResponse":protected]=> NULL ["facebookCurl":protected]=> object(Facebook\HttpClients\FacebookCurl)#6 (1) { ["curl":protected]=> NULL } } } ["graphVersion":protected]=> string(4) "v2.3" ["lastRequest":protected]=> NULL } ["urlDetectionHandler":protected]=> object(Facebook\Url\FacebookUrlDetectionHandler)#10 (0) { } ["persistentDataHandler":protected]=> object(Facebook\PersistentData\FacebookSessionPersistentDataHandler)#9 (1) { ["sessionPrefix":protected]=> string(6) "FBRLH_" } ["pseudoRandomStringGenerator":protected]=> object(Facebook\PseudoRandomString\McryptPseudoRandomStringGenerator)#11 (0) { } }
但是在$ accessToken = $ helper-> getAccessToken()上没有结果; var_dump($ accessToken);
有人可以帮忙吗?
最诚挚的问候和新年快乐:-)
答案 0 :(得分:0)
https://github.com/facebook/php-graph-sdk/issues/958
petertoth0507于2018年5月25日发表评论
解决方案如下: 在过去,getAccessToken函数无需参数即可工作: $ accessToken = $ helper-> getAccessToken();
当前,您必须设置回调URL,例如: $ accessToken = $ helper-> getAccessToken('https://www.classfund.hu/index.php?r=site/fblogincallback');
同时,您必须在https://developers.facebook.com/apps/页的应用程序属性“产品”->“设置”->“有效的OAuth重定向URI”字段中设置相同的参数。
设置上述参数后,身份验证将再次正常运行。...