I am attempting to retrieve a user's news feed using the JavaScript SDK. This works fine in the Test Console but as soon as I try it on my site it doesn't work.
FB.api('/me/home', 'get', function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert(response);
}
});
I understand that the alert will just return "[object]" but I'm just trying to get the API call working right now. Any help would be greatly appreciated
Are you asking the user for the read_stream
permission. You can't see the user's feed without that permission. That could be the reason for the error.
Alert the actual error to make debugging easier:
alert( response.error );
Or even better, use console.log
:
FB.api('/me/home', 'get', function(response) {
console.log(response);
});
Calling your function too early could be causing the call to fail. Try wrapping your function in the fbAsycInit
function:
window.fbAsyncInit = function() {
FB.api('/me/home', 'get', function(response) {
console.log(response);
});
};