Reputation: 33946
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?
Upvotes: 0
Views: 606
Reputation: 17478
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>
Upvotes: 2
Reputation: 28470
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".
Upvotes: 1