Reputation: 621
I recently started to work with the Facebook API and I'm have some problems with showing the $_COOKIE["fbs_APP_ID"] cookie. Even when I log in with facebook and reload the same page the cookie is still showing null.
Here is my code. I took out my app id for security purposes but just assume that I have put it down in my real script.
By the way, I have in fact registered my application on facebook and such.
<html>
<head>
<title>My Facebook Login Page</title>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'APP_ID',
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
FB.Event.subscribe('auth.login', function(response){
window.location.reload();
document.getElementById("messageContainer").innerHTML = "Reloaded successfully!";
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
<div class="fb-login-button">Login with Facebook</div>
<div id = "messageContainer"> </div>
<div id = "cookieCheck"> <?php echo var_dump($_COOKIE["fbs_APP_ID"]) ?></div>
</body>
Upvotes: 1
Views: 257
Reputation: 764
on oauth2 you will get cookie by $_COOKIE["fbsr_APP_ID"] not fbs..
if you want to get access_token use response:
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var access_token=response.authResponse.accessToken
};
})
Upvotes: 1