开发者

Facebook Like Box - monitoring clicks

开发者 https://www.devze.com 2023-01-21 23:24 出处:网络
Is it possible to somehow monitor who \"Likes\" my Facebook page, by intercepting the clicks in the Facebook Like Box?

Is it possible to somehow monitor who "Likes" my Facebook page, by intercepting the clicks in the Facebook Like Box?

http://developers.facebook.com/docs/reference/plugins/like-box

I would like to find out if the user who comes to my site already likes it, and enable some additional functionality based on this (fo开发者_如何学Cr example, less advertising).


You can use the javascript sdk to subscribe to the event edge.create. See the documentation here for that: http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe

FB.Event.subscribe('edge.create', function(response) {
  // A user liked the item, read the response and handle
});

Note, this will only work if you are using the xfbml version of the Like box. It wont work on the iframe version.


I don't know how to fetch just all people that have pressed the like button for an object, but you can subscribe to the like-button-press event. You can then use the information about the current user, and save it to your own database. The event that you are listening to is edge.create, and you do that with FB's own FB.Event.subscribe. It could look something like this:

window.fbAsyncInit = function() {
    FB.init({
      appId  : 'xxxxxxxxxxxxxxxxxxxxxxxxx',
      status : true, // check login status
      cookie : true, // enable cookies to allow the server to access the session
      xfbml  : true  // parse XFBML
    });
    FB.Event.subscribe('edge.create', function(href, widget) {
        FB.api('/me', function(response) {
            alert(response.first_name + " " + response.last_name + ":" + response.id +" pressed " + href); // Replace this with an ajax call to your server
        });
    });
};


It's embedded in an iFrame, so from the way they suggest you implement it, no it isn't possible.

However if you take a look at the code:

http://www.facebook.com/plugins/likebox.php?href=http://www.facebook.com/platform&width=292&colorscheme=light&connections=10&stream=true&header=true&height=587

There may be a way if you fiddle with it to call another function on the like buttons click that calls an ajax function you determine if you host all the code on your site, although FB probably has put things in place to not make that possible, or if it is it may be against T&C so worth checking out.

0

精彩评论

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