How to detect Facebook Like button pressed and trigger event?

删除回忆录丶 提交于 2019-12-03 03:50:23

When a Facebook tab is loaded, the fb_sig_is_fan parameter is passed in specifying if the current user viewing the tab is a fan. Clicking on the Like button will trigger a reload of the tab content, resulting in an updated fb_sig_is_fan being passed in so the app can decide to show a different image.

Actually information if user is page fan or not exists in signed request. Since you need firstly to decode signed request like it is here:

 $signed_request = $_REQUEST["signed_request"];
 list($encoded_sig, $payload) = explode('.', $signed_request, 2); 
 $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

And after that access page liked variable:

$pageLiked = $data['page']['liked'];

Now FB is on the way of deprecating FBML so don't consider <fb:visible-to-connection> as something that will work for a long base.

http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

FB.Event.subscribe('edge.create', function(response) {
// do something with response.session
});
Joby Joseph

One can detect when a user clicks on like button using edge.create. Also if the user has already liked the page, it can detected using FQL Like Table.

<fb:visible-to-connection>
put here code for users that like the page (no <fb:comments>) 
</fb:visible-to-connection>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!