I’ve rechecked my code many times but i am unable to display the access token on the page using the FB.login function. Everything works fine, FB.ui gets me the access token in the return url and the status checks are all fine but the access token doesn’t show up in the tokendiv when the user logs in through FB.login. Please tell me what i’m doing wrong !
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js">
</script>
<script>
FB.init({
appId:'113381182103752', cookie:true,
status:true, xfbml:true
});
FB.getLoginStatus(function(response) {
if(response.status=="connected")
{
document.getElementById("status").innerHTML="User is connected";
}
else if(response.status=="notConnected")
{
FB.ui({
client_id: '113381182103752',
method: 'oauth',
redirect_uri: 'http://127.0.0.1:8888/test2.php',
response_type: 'token'
});
document.getElementById("status").innerHTML="User is logged in but not connected";
}
else if(response.status=="unknown")
{
FB.login(function(response) {
if(response.authResponse)
{
var token = response.authResponse.accessToken;
document.getElementById("tokendiv").innerHTML=token;
}
});
document.getElementById("status").innerHTML="User is logged out";
}
});
</script>
<div id="tokendiv"></div>
<div id="status"></div>
</div>
</body>
Try writing
instead of
If you don’t do that you won’t get the response.authResponse in the login function, but the old response.session which should no longer be valid.