Here is a routine that searches all posts of a given user via Facebook Graph API
, displays the time that was posted and the message, description and post type in DIV
:
FB.api(
{
method: 'fql.query',
locale: 'pt_BR',
query: 'SELECT post_id, source_id, message, created_time, type, description, permalink FROM stream WHERE source_id = ' + friend_data[i].id + ' LIMIT 50'
},
function(posts){
if(posts.length>0){
var divFriendsPost = document.getElementById('friend' + posts[0].source_id);
var friendPosts = '';
for(var j=0; j < posts.length ; j++) {
var d = new Date(0);
d.setUTCSeconds(posts[j].created_time);
dateFormat = [d.getDate(), (d.getMonth()+1), d.getFullYear()].join('/');
timeFormat = [d.getHours(), d.getMinutes(), d.getSeconds()].join(':');
if(posts[j].permalink != null && posts[j].permalink != '') {
friendPosts += '<a href="' + posts[j].permalink + '" target="_blank">';
}
friendPosts += '<div class="singlePost">';
friendPosts += '<div class="spLeft">';
friendPosts += '<p>' + dateFormat + '</p>';
friendPosts += '<p>' + timeFormat + '</p>';
friendPosts += '</div>';
friendPosts += '<div class="spRight">';
friendPosts += '<p>' + posts[j].message + '(' + posts[j].type + ')</p>';
friendPosts += '<p>' + posts[j].description +'</p>';
friendPosts += '</div>';
friendPosts += '</div>';
if(posts[j].permalink != null && posts[j].permalink != '') {
friendPosts += '<div>';
friendPosts += '<iframe height="400" src="' + posts[j].permalink + '"></iframe>';
friendPosts += '</div>';
friendPosts += '</a>';
}
}
var newNode = document.createElement('div');
newNode.innerHTML = friendPosts;
divFriendsPost.appendChild(newNode);
}
}
);
The problem is that it is not enough to present this information in the DIV, since most of the time the post is a photo sharing or publication, for example.
I had the idea of putting the link (permalink) in iframe
under the DIV, but the console returns the following error:
Refused to display ' link ...' in a frame because it set 'X-Frame-Options' to 'DENY'.
I believe facebook blocks this kind of action.
How to solve this problem, ie simply show only the post (without anything that surrounds it on facebook page) under the DIV?