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>
- You don't want
function
in front ofFB.Event.subscribe()
. - 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>
精彩评论