How to comment on an embedded facebook post on a website without leaving it

I recently made a fan page and I used inline code from one of my fan page posts on my website.

So now it shows the post on my site and the number of likes, but I would like to show the current existing comments that this particular post received. Right now, it just displays a comment button and if I click it takes me to the fan page just for the comment.

So what do I need

1 - Comment inline post without leaving facebook website.

2 - Displays all current existing comments.

the image right now looks like

enter image description here

+3


source to share


2 answers


It's very simple. First, you need to login and request publish_stream permission. After the user is logged in, you simply want to display a button that triggers a function named comment, passing in an ID (corresponding to the user of the object to be commenting on).

You will also need an input field to insert a comment (of course) and with jquery.value we will get the value of the input field.

PS: enter NAME and ID in the message input field. I don't remember which one, put both of them.



After receiving the variables, we will call FB.api specifying the id and comentario variables, rather than getting a response to process the result (if you like), you can try to reload the comment plugin or refresh the page.

function comment(id) {
                    var id = id;
                    var comentario = document.getElementById("message").value;
                    FB.api("/"+id+"/comments","POST",
                    {
                    "message": comentario
                    },
                    function (response) {
                                          if (response && !response.error) {
                                         alert('Comentado !');
                                        } else {
                                         alert('Erro !');
                                               }
                                    });
                    $("#atividade").html('COMENTADO');
        }

      

It's very simple and fun, but you will need to get the facebook platform authorization to ask users for publish_stream permissions before releasing.

0


source


I think David's answer will just post a new comment, not all comments for comments.

Unfortunately, there is no option to show comments for embedded posts. You need to get the post id, call the api to download all the comments, and thus insert each one. Yes, it's terrible ...

Open the graphical api explorer:
https://developers.facebook.com/tools/explorer/



Enter {post-id} / comments in the GET tab and submit it to see an example response.

And that you are pasting comments:
https://developers.facebook.com/docs/plugins/embedded-comments

I don't think loading all comments from all posts will be good. I suggest you create a "see comments" button that calls the api. After that you can create input text for new comments like David said.

0


source







All Articles