I am using the FB JavaScript SDK and followed the FB tutorial exactly. I have added the login button, logged in with my FB account and am trying to make a very basic FB.api call but am not getting a proper response even after I login with facebook. Here’s the code:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '291660820848913',
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
FB.api('/me', function(response) {
alert(response.name);
});
};
(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>
This gives me an alert that says “undefined”. Am I doing something wrong?
This should only be done if you know the user is authenticated. You should put a call to
FB.getLoginStatus()prior to calling theFB.api().