9

I don't understand why I'm getting this exceptions:

Session not active, could not store state.

The code is:

<?php

require 'vendor/autoload.php';

use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;

FacebookSession::setDefaultApplication('foo', 'baz');

$helper = new FacebookRedirectLoginHelper('bar');
$loginUrl = $helper->getLoginUrl();

?>

Please help.

SBel
  • 3,315
  • 6
  • 29
  • 47

1 Answers1

40

You need to start a session using session_start() for the Facebook SDK to work correctly. Please add this to your code to fix the issue.

Example:

<?php

session_start();

require 'vendor/autoload.php';

use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;

...
Niraj Shah
  • 15,087
  • 3
  • 41
  • 60
  • If you don't want to use the default $_SESSION to store the state, you can [extend the storeState class using this linked example](https://github.com/facebook/facebook-php-sdk-v4/issues/39#issuecomment-42363729). The example uses Laravel sessions but you can use whatever you want inside your extension. – Luke Shaheen Sep 25 '14 at 16:44
  • Yupp That worked for me, Thank You So much @Niraj Shah. I forgot to use redirectloginhelper. – Akilsree1 Mar 12 '15 at 06:07
  • 1
    You've got to be kidding me... All this time I was looking into Facebook session... – Slavic Apr 15 '15 at 09:53