API v1.12中如何监听Facebook点赞按钮的点击事件?
关于Facebook API v1.12中监听点赞按钮点击事件的方法
Hey there! Based on the official Facebook developer post from November 2017, here's what you need to know about listening for like button clicks in API v1.12:
Yes, you absolutely can track when a user clicks the Facebook Like button in v1.12. The go-to method uses the Facebook JavaScript SDK's event subscription system.
Here's how to implement it:
- First, make sure you've properly loaded and initialized the Facebook JavaScript SDK with your app ID.
- Use the
FB.Event.subscribe()method to listen for theedge.createevent — this event fires every time a user clicks an official Facebook Like button.
Here's a quick code example to get you started:
// After initializing the SDK FB.Event.subscribe('edge.create', function(targetUrl) { // Add your custom logic here — like logging the event, updating your UI, or sending data to your backend console.log('User liked this URL:', targetUrl); });
A couple of important notes:
- This only works with the official Facebook Like button component (the one rendered via the
<div class="fb-like"></div>tag). Custom-built like buttons won't trigger this event. - While the 2017 post announced changes to some developer offerings, the
edge.createevent was still fully supported in v1.12. Later API versions did adjust some event permissions, but that doesn't affect v1.12 functionality.
内容的提问来源于stack exchange,提问作者Nikita Glusuchenko
相关产品推荐
相关产品推荐

