2016-09-02 3 views
3

페이스 북은 정말 멋지게 시작했습니다. 사용자가 클릭하여 옵트 인하도록 페이지를 리디렉션하는 방법을 알아 내려고 노력했습니다. 자, 나는 진지하게 자바에 대한 좋은 점이 없다. PHP는 내 일이다.Facebook Send-To-Messenger 이벤트 리스너

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

작업 코드 : CONSOLE.LOG을 쫓아 및 리디렉션하지만 사용자가 버튼을 클릭하고를 트리거 할 때 제가하고 싶은 것은 뭔가를 할 것입니다 것입니다

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

send_to_messener 버튼으로 옵트 인하십시오.

그래서 나는 다시 ---도 ---

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

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

을 시도, 아무 일 없다 - 사람이 올바른 방향으로 가리킬 수있는 단서가있는 경우, 나는 그것을 감사하겠습니다 .. 감사!!

답변

0

다시보고 나서 알아 냈습니다.

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

'사용자가 이미 로그인되어 "메신저로 보내기"를 클릭하면 is_after_optin'가 true로 설정되어 있지 않습니다. – Flimm

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> 
+0

그래, 내가 말한 바로 그 일이있어. 우리가 지금 가지고있는 문제는 그들이 이미 "optin"하고 bot와 대화를 나눈 것입니다 ... 그것은 리다이렉트하지 않을 것입니다. 그래서 우리는 해결 방법을 찾아 내려고 노력해 왔습니다. – Michael

+0

사용자가 Facebook에 로그인하지 않아도 clicked가 실행됩니다. – Flimm

+0

'messenger_app_id'를 어떻게 또는 어떻게 얻습니까? –