Facebook SDK returned an error: Cross-site request forgery validation failed. The “state” param from the URL and session do not match

后端 未结 25 1066
南方客
南方客 2020-12-01 01:37

i\'m trying to get Facebook user id using the php sdk like this

$fb = new Facebook\\Facebook([
    \'app_id\' => \'11111111111\',
    \'app_secret\' =>         


        
25条回答
  •  心在旅途
    2020-12-01 02:27

    you receive this error if you origin hostname is different than the target hostname once authenticated.

    $loginUrl = $helper->getLoginUrl('http://MyWebSite', $permissions);
    

    with this statement, if the visitor on your website used http://www.mywebsite.com/ the cross-site error will be raised.

    You must ensure that origin and target hostname are exactly the same, including the eventual www prefix.

    Fixed version:

    $loginUrl = $helper->getLoginUrl('http://'.$_SERVER['SERVER_NAME'], $permissions);
    

提交回复
热议问题