Facebook PHP SDK v4.0 FacebookJavaScriptLoginHelper returns NULL

Im working on my localhost using the FB PHP SDK 4.0. I was able to complete the login using the JS SDK, now I'm trying to access some information through the PHP SDK.

On each page I add this js and php code.

Javascript

window.fbAsyncInit = function() {
  FB.init({
    appId      : 'app-id',
    xfbml      : true,
    version    : 'v2.1',        
    status     : true,
    cookie     : true

  });

  FB.getLoginStatus(function(response) {
    statusChangeCallback(response);
  });
};

(function(d, s, id){
   var js, fjs = d.getElementsByTagName(s)[0];
   if (d.getElementById(id)) {return;}
   js = d.createElement(s); js.id = id;
   js.src = "//connect.facebook.net/en_US/sdk.js";
   fjs.parentNode.insertBefore(js, fjs);
 }(document, 'script', 'facebook-jssdk'));

Php

session_start();
//NO COMPOSER
require '/path-to/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookJavaScriptLoginHelper;

FacebookSession::setDefaultApplication('app-id', 'app-secret');

$helper = new FacebookJavaScriptLoginHelper();
try {
   $session = $helper->getSession();
} catch(FacebookRequestException $ex) {
  // When Facebook returns an error
} catch(\Exception $ex) {
  // When validation fails or other local issues
}
if ($session) {
  // Logged in.
}

In JavaScript, when I call FB.getLoginStatus (), it gives me a successful answer. However, on the PHP side, every time I upload $helper, it returns with ["state"]=> NULL. I made sure my application id matches.

I thought they were exchanging data through cookie, but when I look at my cookies and site data, I can’t find anything relevant. Or do I need an access token to do this?

+4
1

, Firefox. Chrome: Google Chrome cookie ( localhost), -enable-file-cookie. , Chrome cookie, IP--127.0.0.1- .

. fooobar.com/questions/1558668/...

+2

All Articles