开发者

How to detect if someone is the first to Facebook Like a page

I was wondering how I would go about detecting if when a person likes a post on my blog that they are first person to like it.

I 开发者_运维知识库tried this but it does not seem to work.

Any help/ideas?

<script type='text/javascript'>
  function FB.Event.subscribe('edge.create', function(response) {
  // user clicked like
alert('Thank you for liking this post');
  var query = FB.Data.query('SELECT like_count FROM link_stat WHERE url="' + window.location + '"');

  query.wait(function(rows) {
    if ( ! rows[0].like_count ) {
       alert('Congrats - You are the first person to like this');
    }
  });
});
</script>


  1. You don't want function in front of FB.Event.subscribe().
  2. Igy is right: You need to check for a Like count of 1, not 0, because the query is run after the Like has occurred.

The following should work, assuming you've called FB.init() before this, and your Like Button URL is the same as window.location.

<script type='text/javascript'>
  FB.Event.subscribe('edge.create', function(response) {
    // user clicked like
    alert('Thank you for liking this post');
    var query = FB.Data.query('SELECT like_count FROM link_stat WHERE url="' + window.location + '"');

    query.wait(function(rows) {
      if (rows[0].like_count == 1) {
        alert('Congrats - You are the first person to like this');
      }
    });
  });
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜