0

Lets say I am having 5 news articles on my website and 2 registered users. Each news article is having an FB like button. I want to insert the username and article name in my own database whenever the user likes one of the articles. How can this be done?

If it would have been a normal submit button (instead of FB like button) then i would have simply added an onclick event to call a javascript function which in turn sends an ajax request to a php file which inserts the row in the database with the required field.

Can I add an onClick event with FB like button? if not then is there an alternative?

  • 1
    What if people unlike it, like it elsewhere, use a Facebook API or another way not through your page? –  Apr 04 '11 at 21:09
  • If I get a way to insert rows on liking then I can always delete a row on unliking.. isn't it. I don't care if its liked elsewhere. – Ankit Prasad Apr 04 '11 at 21:11
  • I don't think you can do it. It is loaded as an iframe, though I am not sure if Facebook Engineers have something in store for this as well. – w2lame Apr 04 '11 at 21:21
  • This is possible, I've found a reference article at http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/ but may be somebody can help me with already tested block of codes, although i'm trying from my end .. thanks – Ankit Prasad Apr 04 '11 at 21:51

1 Answers1

2

A slightly hack-y way to go about it would be to attach an onclick event handler to the iframe container to trigger an event whenever a user clicks like on page.

I haven't worked with the API that much, but can't you use this: edge.create -- fired when the user likes something (fb:like)? http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

KunalB
  • 29
  • 2
  • 1
    yes sure edge.create is the thing which I was looking for. My problem is solved, thanks. by the way I found a really helpful article here http://www.saschakimmel.com/2010/05/how-to-capture-clicks-on-the-facebook-like-button/ – Ankit Prasad Apr 04 '11 at 23:50