Facebook Grap APU $ accessToken = $ helper-> getAccessToken(),无值 [英] Facebook grap APU $accessToken = $helper->getAccessToken() with no value
问题描述
我被困住了...一切看起来都正确,但是不起作用.在我来自Facebook开发人员的应用程序中使用了调试访问令牌进行了尝试,它工作得很好,因此与代码的其余部分无关.
I'm stuck... Everything looks correct but it does not work. Tried with a debug access token from my app at facebook developer and it works great so its not an issue with the resto of the code.
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,结果是:
Setting $accesstoken with a valid token the code works so im not getting the access token. I can dump $helper and the result is:
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);
But no result on $accessToken = $helper->getAccessToken(); var_dump($accessToken);
任何人都可以帮忙吗?
最诚挚的问候和新年快乐:-)
Best regards and a happy new year :-)
推荐答案
https://github.com/facebook/php-graph-sdk/issues/958
petertoth0507于2018年5月25日发表评论
petertoth0507 commented on 25 May 2018
解决方案如下:在过去,getAccessToken函数无需参数即可工作:$ accessToken = $ helper-> getAccessToken();
The solution is in the following: In the old times the getAccessToken function worked without parameter: $accessToken = $helper->getAccessToken();
当前,您必须设置回调URL,例如:$ accessToken = $ helper-> getAccessToken(' https://www.classfund.hu/index.php?r = site/fblogincallback ');
In current time you must set the callback URL, example: $accessToken = $helper->getAccessToken('https://www.classfund.hu/index.php?r=site/fblogincallback');
同时,您必须在 https://developers.facebook.com/apps/页,位于应用程序属性的产品"->设置"->有效的OAuth重定向URI"字段中.
In parallel you must set the same parameter at https://developers.facebook.com/apps/ page at your application property, Products->Settings->Valid OAuth Redirect URIs field.
设置上述参数后,身份验证将再次正常运行....
When I set the above mentioned params the authentication operating properly again....
这篇关于Facebook Grap APU $ accessToken = $ helper-> getAccessToken(),无值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!