Double check and make sure that the variable comm_id is generated with both the user ID of the person who posted the message and the identifier of the message itself, with an intermediate sign, for example, USERID_POSTID. This is how facebook gives you if you call on the api chart
$post_url = "https://graph.facebook.com/" . $user_id . "/posts?access_token=". urlencode($access_token);
Not sure if you get comm_id from another source or not. Also noticed in your code
access_token : "<?php echo $access_token ?>"
After the echo, you forgot the half-column. It must be
access_token : "<?php echo $access_token; ?>"
Hope this helps. I see that you use a lot of jquery to perform similar functions. I like to stick with the w / server side code for such things, I feel that for some reason it is more stable.
Here is how I did it. I have a similar button like this -
echo '<div id="like_container-'.$i.'"> <div id="like_count">'.$num_likes.'</div>' <a href="javascript:void()" onclick="fb_Like(\''.$post_id.'\',\''.$access_token.'\','.$num_likes.','.$i.')"><div class="unliked"></div></a> </div>';
and fb_Like () is an ajax call, something like this -
function fb_Like(post_id, token, num_likes, id){ $.ajax({ type: "GET", url: "likepost.php", data: 'id='+post_id+'&token='+token+'&likes='+num_likes, success: function(html) { $("#like_container-"+id).empty().html(html); } }); }
And likepost.php page is a script similar to the one on this page
How Facebook Post externally using Graph Api - example
This worked very well for me. It also allows me to update the number of likes that the column has on the front side to the right above a similar button, if it was done. Good luck
UPDATE
If you want to check if the user likes the message, it is quite simple with the facebook api schedule
//Create Post Url $post_url = "https://graph.facebook.com/" . $Page/User_id . "/posts?access_token=". urlencode($access_token); //Get Json Contents $resp = file_get_contents($post_url,0,null,null); //Store Post Entries as Array $the_posts = json_decode($resp, true); foreach ($the_posts['data'] as $postdata) { foreach ($postdata['likes']['data'] as $like){ if($like['id']==$user){ $liked=1; }else{continue;} } if($liked==1){ //do something } }
This assumes that you already have the facebook user ID for the registered user, in this example it is stored in the $ user variable.