首页 文章

Facebook Send-To-Messenger事件监听器

提问于
浏览
4

Facebook推出了一些非常酷的东西,我一直试图找出如何让用户点击和选择加入页面重定向 . 现在,我对java没有任何好处,php是我的事 .

参考:https://developers.facebook.com/docs/messenger-platform/plugin-reference/send-to-messenger#event

工作守则:

FB.Event.subscribe('send_to_messenger', function(e) {
// callback for events triggered by the plugin
console.log('inside the send_to_messenger');  
window.top.location = 'http://google.com';
});

这将启动console.log和重定向,但我想要做的是当用户单击按钮并使用send_to_messener按钮触发选择时执行某些操作 .

所以我试过了

FB.Event.subscribe('clicked', function(e) {
// callback for events triggered by the plugin
console.log('user clicked button');  
window.top.location = 'http://google.com';
});

---也---

FB.Event.subscribe('send_to_messenger', function(e) {
FB.Event.subscribe('clicked', function(e) {
// callback for events triggered by the plugin
console.log('user clicked button');  
window.top.location = 'http://google.com';
}});

再一次,没有任何效果 - 如果有人有一个可以指向正确方向的线索,我会很感激..谢谢!!

2 回答

  • 0

    再看一遍之后,我想通了 .

    if (response.is_after_optin == true ){ // do something }
    
  • 0

    //完整的工作示例:

    window.fbAsyncInit = function() {
          FB.init({
            appId: "app_id",
            xfbml: true,
        status: true, 
        cookie: true,
            version: "v2.6"
          });
    
    
          FB.Event.subscribe('send_to_messenger', function(response) {
        if ( response.event == 'clicked' ) {
              // callback for events triggered by the plugin
                window.top.location = 'https://www.messenger.com/t/page_id';
        };
          });
    
        };
    
        (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>
    
    <br>
    <div class="fb-send-to-messenger"
    
      messenger_app_id="app_id" 
      page_id="page_id"
      data-ref="send this info to the app"
      color="blue"
      size="xlarge" >
    </div>
    

相关问题