Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
903 views
in Technique[技术] by (71.8m points)

javascript - Detect when Facebook like button is clicked

I have the following JavaScript code

<div class="fb-like-box" data-href="snip" data-colorscheme="light" 
    data-show-faces="false" data-header="false" data-stream="false" 
    data-show-border="true"></div>

I am trying to detect when the like button is clicked. The above code renders an iframe so my jquery event handler of

$('.fb-like-box > button').on('click', function() { console.log('Clicked'); });

Never fires. I tried wrapping this div and other content in a wrapper div and target that in the $() call but it only fires when the other content is clicked, not the area that is rendered by the Facebook SDK.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v2.3

You just need to subscribe to the edge.create event for likes. See docs for example code.

But as commented, you are not allowed to reward users for liking. Read the platform policy for more information: https://developers.facebook.com/policy/


Update: https://developers.facebook.com/blog/post/2017/11/07/changes-developer-offerings/

edge.create and edge.remove JS SDK Events: These Events will no longer be accessible. As an alternative, you can use our Webhooks and be notified every time someone likes one of your Facebook Pages.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...