I am learning javascript and the Facebook API right now and I am trying to display the users newsfeed. I know the query I need to use but I don’t know how to display the results using javascript. Here is my query
SELECT post_id, actor_id, target_id, message FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me() AND type='newsfeed') AND is_hidden = 0
I am pretty sure a forEach loop to display each result is what I need to do but how would I go about populating each result with the newsfeed post information?
EDIT
Ok here is my new code that does correctly receive the results of the query. Unfortunately, the results just aren’t being shown.
<script>
function showPosts() {
FB.api("/fql?q="+encodeURIComponent("SELECT post_id, actor_id, target_id, message FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me() AND type='newsfeed') AND is_hidden = 0"), function(response, post_id, actor_id, message) {
console.log(response);
var posts = response.data
var postId = post_id.data;
var message = message.data;
for (var i=0; i < posts.length && i < 25; i++) {
var post = posts[i];
markup += '<div>' + post.postId + post.message + '<div/>';
}
document.getElementById('newsfeedposts').innerHTML = markup;
});
</script>
Execute the query via FB.api, and handle the data you’ll be getting back in the callback function.
Execute that in Firefox, look into the Firebug console, and you should get an understanding of how the response is constructed.