尝试执行时-$ helper-> getAccessToken()-给出错误-'跨站点请求伪造验证失败。持久数据中缺少必需的参数“状态””
使用了symfony 3.3和facebook / graph-sdk 5.4
已添加所有域 存在'FBRLH_state' 会议开始
//创建网址
$facebookCallbackUrl = 'https://' . $base . '/' . $_locale . '/fb-callback';
$loginfb = $this->get('app.lmfacebook')->getSigninURL($this->getParameter('fbappid'), $this->getParameter('fbsecretkey'), $facebookCallbackUrl);
<?php
namespace AppBundle\Services\Ukraine;
use Facebook\Facebook;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class LMFacebook extends Controller
{
public static function getSigninURL($fbId, $fbSecret, $callback)
{
$fb = new Facebook([
'app_id' => $fbId,
'app_secret' => $fbSecret,
'default_graph_version' => 'v2.9',
'persistent_data_handler' => 'session'
]);
$permissions = ['email'];
return $fb->getRedirectLoginHelper()->getLoginUrl($callback, $permissions);
}
}
// Facebook回调
/**
* @Route("/{_locale}/fb-callback", name="fb-callback", defaults={"_locale": "ua"}, requirements={"_locale" : "ua|en|ru"})
* @param Request $request
* @param $_locale
* @return mixed
*/
public function fbCallbackAction(Request $request, $_locale)
{
$session = $request->getSession();
$fb = new Facebook([
'app_id' => ********,
'app_secret' => *******,
'default_graph_version' => 'v2.9',
'persistent_data_handler' => 'session'
]);
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken(); // Error
} catch (\Exception $exception) {
$this->logToFile('Facebook returned an error: ' . $exception->getMessage());
exit;
}