如何检测某人是否是第一个在Facebook上点赞的人



我在想,如果一个人在我的博客上点赞了一篇文章,我该如何检测他是否是第一个点赞的人。

我试过了,但似乎不起作用。

任何帮助/想法吗?

<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. 你不希望functionFB.Event.subscribe()前面。
  2. Igy是正确的:您需要检查Like计数为1,而不是0,因为查询是在Like发生后运行的。

下面应该工作,假设你在此之前调用了FB.init(),并且你的Like按钮URL与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>

最新更新