0

I'm considering implementing Facebook's comments plugin on my site. The problem is that I need to know the pages on my site where a user has commented.

I have read Facebook's documentation but I don't find a proper permission to know this.

Is it possible to know which URLs a user has commented? In such case which permissions does my app need?

2 Answers 2

2

I know you have already accepted an answer, but i think this will help you.

You can first generate the code for Facebook Comments here.

For each page that you implement the comments plugin in, you'll be providing a href of the page the user is reading/visiting, as it is required by the plugin.

You can use the Javascript SDK to listen to Facebook events, for comments specifically you have the comment.create event, which is fired every time a comment is made. This event passes a response object to its callback function, which contains the href mentioned previously, and the commentID of the comment just generated. Hence you can easily track which page(url) a user has commented on.

Example (see how we can listen to the comment.create event):

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'YOUR_APP_ID', // App ID
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

    // Additional initialization code here, this is where we listen to events
    FB.Event.subscribe('comment.create',
      function(response) {
        alert('You commented on the URL: ' + response.href + 'CommentID: ' + response.commentID);
        // do an ajax call to server to store user,commentID,href info if you require
      }
    );
  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>
Sign up to request clarification or add additional context in comments.

8 Comments

It helps a lot. With this I could theoretically use AJAX in place of the alert to insert the HREF and the CommentID into my database every time a comment is made. Right? Just I won't be able to know the comment's text.
i have already mentioned in the code that you can do ajax call, so that should be clear. you can also get the comment's text by calling the graph api with the commentID, simply call : https://graph.facebook.com/commentID
Is there a way to echo the comment's ID together with the comment's box ID?
i'm not aware of any comment box id, where did you see that?
In the alert box, where it says commentID: that ID is actually the comment's box ID. I get the same for all comments on the box. You can see it here: lujanventas.com/test.php
|
1

Call

graph.facebook.com/USER_ID/feed&fields=link 

for each user you want to query about. This call returns id, name and the link field which is a url to the object commented on. Not all posts will have a link field so you need to check for null. You can then compare the link field to find matches with your urls.

The feed includes comment posts from the Comment Box Plugin only in the case of a user leaving the “Post to Facebook” box checked when she posts a comment.

You need to ask users for read_stream permission.

This all assumes you know know who the user is. You need to keep track of those users on your side since there is no way to query FB's API for "users who have commented on my site".

2 Comments

Thanks, can I ask you something else? Is it possible knowing an object's IDs to get user ids from those who commented including those who haven't checked "post to facebook" box?
I don't think it's possible but it's risky to confirm something as impossible:). I haven't seen it documented in the API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.