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();
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) {
} catch(\Exception $ex) {
}
if ($session) {
}
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?