0

I use facebook's example code and it returns 0. I found this in the error log. "CSRF state token does not match one provided." When i click login page just reload and generates a new state and code.

I have searched on google and I tried many things but it didn't work.

<?php
  // Remember to copy files from the SDK's src/ directory to a
  // directory in your application on the server, such as php-sdk/
  require_once('php-sdk/facebook.php');

  $config = array(
    'appId' => 'YOUR_APP_ID',
    'secret' => 'YOUR_APP_SECRET',
    'allowSignedRequest' => false // optional but should be set to false for non-canvas apps
  );

  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();
?>
<html>
  <head></head>
  <body>

  <?php
    if($user_id) {

      // We have a user ID, so probably a logged in user.
      // If not, we'll get an exception, which we handle below.
      try {

        $user_profile = $facebook->api('/me','GET');
        echo "Name: " . $user_profile['name'];

      } catch(FacebookApiException $e) {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
        $login_url = $facebook->getLoginUrl(); 
        echo 'Please <a href="' . $login_url . '">login.</a>';
        error_log($e->getType());
        error_log($e->getMessage());
      }   
    } else {

      // No user, print a link for the user to login
      $login_url = $facebook->getLoginUrl();
      echo 'Please <a href="' . $login_url . '">login.</a>';

    }

  ?>

  </body>
</html>
Slaffe
  • 47
  • 1
  • 7
  • is it on live server or local host? If localhost what is the domain name you have provided on the setting page ? – Abhik Chakraborty Apr 20 '14 at 15:28
  • Please tell [which of the many suggestions](http://stackoverflow.com/search?q=%22CSRF+state+token+does+not+match+one+provided.%22+%5Bphp%5D) did not work for you (with reference and at which point). If you need support for facebook demo code from the facebook website, please contact facebook support directly as well. – hakre Apr 20 '14 at 15:33
  • It's live! @AbhikChakraborty I only have my domain on web url and my app domain like example.com. The URL I use the app on is dynamic generated.. – Slaffe Apr 20 '14 at 16:21
  • Have you tried this as well: http://stackoverflow.com/questions/19679318/fb-login-error-csrf-state-token-does-not-match-one-provided – Tobi Apr 22 '14 at 08:32

0 Answers0