I’ve been racking my brains for ages now on this problem. After loading the JavaScript SDK I cannot make any GET calls to the the graph API. I’m attempting to use /me/home but I’ve tried /me as well for debugging purposes. The strange thing is, if I check the user’s login status it return’s an access token which I can use to retrieve the news feed perfectly in the address bar. However, as soon as I make a GET call to the Graph API using JavaScript I get:
“An active access token must be used to query information about the current user.”
Also I can make POST call the the user’s feed using SDK perfectly fine. Finally, I have checked to make sure I have the read_stream permission.
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo($facebook_key); ?>', // App ID
channelUrl : '//'+window.location.hostname+'/channel.php', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// listen for and handle auth.statusChange events
FB.Event.subscribe('auth.statusChange', function(response) {
if (response.authResponse) {
// user has auth'd your app and is logged into Facebook
console.log(response);
} else {
location.href='welcome.php';
};
});
FB.getLoginStatus(function(response) {
console.log(response);
});
//get Facebook news feed
FB.api('/me/home', 'get', function(response) {
console.log(response);
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
//status update function
function post (form) {
var status = form.status.value;
FB.api('/me/feed', 'post', { message: status }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Status updated');
};
});
};
I would try moving your call to /me into your FB.getLoginStatus function:
I think the issue is, your call to the api is firing before the authentication is confirmed. Hopefully moving this function into the getLoginStatus callback should resolve this issue.
You can see more examples here https://developers.facebook.com/tools/console/