我正在尝试将facebook Messenger发送给Messenger'按钮进入我的网站。到目前为止,我一直在进行更改,按钮偶尔出现,但大部分时间都没有。
我需要加载的代码在这里:
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: Meteor.settings.public.FacebookAppId,
xfbml: true,
version: "v2.6"
});
console.log('something in the fb init worked')
FB.Event.subscribe('send_to_messenger', function(e) {
console.log("messenger_checkbox event");
console.log(e);
if (e.event == 'rendered') {
console.log("Plugin was rendered");
} else if (e.event == 'not_you') {
console.log("User clicked 'not you'");
} else if (e.event == 'hidden') {
console.log("Plugin was hidden");
}
});
if (typeof (FB) != 'undefined'&& FB != null) { FB.XFBML.parse(); }
console.log('This then worked as well')
};
(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/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div class='react' id="react-root"></div>
</body>
似乎只要按钮没有加载,就不会调用FB.Event.subscribe函数。
加载实际按钮的代码如下:
<div className="fb-send-to-messenger"
data-messenger_app_id={Meteor.settings.public.FacebookAppId}
data-page_id={Meteor.settings.public.FacebookPageId}
data-ref="PASS_THROUGH_PARAM"
data-color="blue"
data-size="standard">
</div>