Facebook does not allow the presentation of posts in iFrames?

0

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?

    
asked by anonymous 11.02.2014 / 12:43

2 answers

1

You do not need to create an iFrame with the Facebook post. You can use Facebook Embedded Posts .

It automatically creates an iFrame with the post you want. Just pass the link.

    
11.02.2014 / 18:02
2

This is because accessing the page's HTML has the following header

x-frame-options:DENY

This explicitly tells the browser that you do not want the site to be viewed within an Iframe. It is common to do this to force people to access the site through the URL of the site, not the url of others and, of course, for security reasons , and avoid, for example, that it is easy to steal passwords when trying to make the person think that she really is on Facebook.

The solution for you to resolve this is to use the official Facebook API. They already have buttons for likes, comments and the like. What you are doing, incidentally, if not via your own API, is explicitly prohibited under the terms of use of Facebook.

    
11.02.2014 / 12:57