Like button will not fire edge.create or edge.remove

扶醉桌前 提交于 2019-12-11 04:23:53

问题


I'm very much a beginner....

I can't get edge.create or edge.remove to fire when a like button is clicked. I see others have posted this problem too, going back to 2011, with no solution I can see.

My code is as follows....

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<div id="fb-root"></div>
<script>

(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=XXX";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

FB.Event.subscribe('edge.create',
    function(response) {
        alert('You liked the URL: ' + response);
    }
);

FB.Event.subscribe('edge.remove',
    function(response) {
        alert('You UNliked the URL: ' + response);
    }
);

</script>
<fb:like href="https://www.facebook.com/XXX" send="true" width="450" show_faces="true"></fb:like>

</body>
</html>

回答1:


You’re just to impatient … :-)

In your code, you don’t wait for the Facebook SDK to load, which is done asynchronously the way you put it in your code. So when FB.Event.subscribe is called, the SDK is not yet initialized, and so that just fails. (Does it fail silently, or did you just forget to look into your browsers error console …?)

Put the code following the loading of the SDK into a window.fbAsyncInit handler, like shown here: https://developers.facebook.com/docs/reference/javascript/



来源:https://stackoverflow.com/questions/10952042/like-button-will-not-fire-edge-create-or-edge-remove

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!