Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Double check and make sure your variable comm_id is formated with both the user id of the person who posted the post, and then the id of the post itself, with an underscore in between, like this - USERID_POSTID. This is how facebook gives it you if you call to the graph api </p> <pre><code>$post_url = "https://graph.facebook.com/" . $user_id . "/posts?access_token=". urlencode($access_token); </code></pre> <p>Not sure if you're getting comm_id from another source or not. Also noticed in your code</p> <pre><code>access_token : "&lt;?php echo $access_token ?&gt;" </code></pre> <p>You forgot a semi-colon after the echo call. Should be this</p> <pre><code> access_token : "&lt;?php echo $access_token; ?&gt;" </code></pre> <p>Hope this helps. I see you're using a lot of jquery to do the like functionality. I like to stick w/ server side code for stuff like this, I feel that it's more stable for some reason.</p> <p>This is how I did it. I have a like button like this - </p> <pre><code>echo '&lt;div id="like_container-'.$i.'"&gt; &lt;div id="like_count"&gt;'.$num_likes.'&lt;/div&gt;' &lt;a href="javascript:void()" onclick="fb_Like(\''.$post_id.'\',\''.$access_token.'\','.$num_likes.','.$i.')"&gt;&lt;div class="unliked"&gt;&lt;/div&gt;&lt;/a&gt; &lt;/div&gt;'; </code></pre> <p>and fb_Like() is an ajax call, something like this -</p> <pre><code>function fb_Like(post_id, token, num_likes, id){ $.ajax({ type: "GET", url: "likepost.php", data: 'id='+post_id+'&amp;token='+token+'&amp;likes='+num_likes, success: function(html) { $("#like_container-"+id).empty().html(html); } }); } </code></pre> <p>And the likepost.php page is a script similar to the one on this page</p> <p><a href="https://stackoverflow.com/questions/11428242/like-a-facebook-post-externally-using-graph-api-example/11432386#comment16949982_11432386">Like a Facebook Post externally using Graph Api - example</a></p> <p>This worked really well for me. It also let's me update the number of likes that the post has on the front end right above the like button if a like has been made. Good luck!</p> <p>UPDATE</p> <p>If you want to check if the user already likes a post, it's pretty simple w/ the facebook graph api</p> <pre><code>//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 } } </code></pre> <p>This assumes that you already have a facebook user id for the logged in user, in this example, stored in the variable $user.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload