0

Facebook SDK v5

Facebook Graph v2.4

I get this error :

Facebook SDK returned an error: Cross-site request forgery validation failed. Required param "state" missing.

Here is my code :

$facebookAppId = Configure::read(('Facebook.appId'));
$facebookAppSecret = Configure::read(('Facebook.appSecret'));

$this->fb = new Facebook(['app_id' => $facebookAppId,
                          'app_secret' => $facebookAppSecret,
                          'default_graph_version' => 'v2.4',
                          'default_access_token' => $facebookAppId.'|'.$facebookAppSecret]);

$helper = $this->fb->getRedirectLoginHelper();

try {
    $accessToken = $helper->getAccessToken();
} catch(FacebookResponseException $e) {
    // When Graph returns an error
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
} catch(FacebookSDKException $e) {
    // When validation fails or other local issues
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
}

Do you have any solution ? Thanks you.

Halvor Holsten Strand
  • 19,829
  • 17
  • 83
  • 99
frenchdev20
  • 695
  • 2
  • 10
  • 18
  • Check if `$_GET['state']` exists and is not empty at that point. If not, check your routing/rewrite configuration, and see if it got lost in there somehow. – CBroe Dec 18 '15 at 19:44
  • Thanks you for your quick reply but my `$_GET['state']` is not empty. I also check that my session is started. Does anyone has had this type of error ? – frenchdev20 Dec 18 '15 at 19:52
  • Is this any use http://stackoverflow.com/questions/31520593/facebook-php-sdk-5-api-2-4-cross-site-request-forgery-validation-failed-r/31542061?noredirect=1#comment51055949_31542061 or perhaps this? https://github.com/facebook/facebook-php-sdk-v4/issues/473 seems to have solved some similar issues for some users. – Steve Dec 19 '15 at 03:45
  • Can you add `session_start()` at the top of all your scripts, before calling any SDK method? Does that solve the issue? – Roemer Dec 30 '15 at 10:12

0 Answers0