Friday, 02 August 2013 23:23

How to comment and like facebook post using Graph Api

Written by 
Rate this item
(0 votes)
Any one can comment,like a facebook post from a website
outside of facebook.following codes shows how one can
implement that in their website.
codes for comment -

FB.api('/'+post_id_here+'/comments', 'POST',{ access_token: token, message: jQuery.trim(jQuery("#msfb-commentbox").val()) }, function(response) {
if (!response || response.error) {
alert("Errors - you are not permitted to comment on that post");
} else {
//post success
location.reload(true);
}
});

here you have to enter post id at first and enter the user entered
comment as value of message paramenter.Also you will
need access token of the user who commenting.you can get token by
javascript sdk FB.login call which i used in one of my post on how
to post to facebook wall by graph api.

following are codes for like.not much difference with above codes -

FB.api('/'+post_id_here+'/likes?access_token='+token+'', 'POST',function(response) {
if (!response || response.error) {
alert("Errors - you are not allowed to like the post");
} else {
//sucess
location.reload(true);
}
});

hope that helps very much.Don't forget to like and share it.
Read 4746 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.

Latest discussions

  • No posts to display.