用户点击SEND-TO-MESSENGER按钮后如何获取PSID?

时间:2017-10-14 15:05:34

标签: facebook facebook-javascript-sdk facebook-messenger messenger facebook-messenger-bot

这是我的代码:

  

window.fbAsyncInit = function() {
  FB.init({
    appId: "xxx",
    xfbml: true,
    version: "v2.6"
  });

  FB.Event.subscribe('send_to_messenger', function(response) {
   // callback for events triggered by the plugin
     console.log('inside the send_to_messenger'); 
     if ( response.event == 'clicked' ) {

     };


  });

};

(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'));

   

现在,我如何获得用户的PSID?

1 个答案:

答案 0 :(得分:1)

您需要订阅messaging_optins webhook事件。单击“发送到信使”按钮后,您应该在事件的sender.id道具中获得PSID。