2016-09-02 22 views
3

Facebookは何か本当にクールなものを立ち上げました。ユーザーがクリックしてオプトインするとページをリダイレクトする方法を見つけようとしています。今、私は真剣にJavaで良いことではない、PHPは私のことです。Facebook Send-To-Messengerイベントリスナー

REFERENCE: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

'。 – Flimm

0

// FULL実施例:ユーザーがすでにログインし、 "メッセンジャーに送る" をクリックしたときにtrueに設定されていないis_after_optin`

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

ええ、それはまさに私が上に言ったことが働いているということです。私たちが今問題にしているのは、彼らがすでに "オプチイン"していて、ボットと会話しているということです。リダイレクトされません。だから、私たちは、回避策を見つけようとしてきました。 – Michael

+0

ユーザーがFacebookにログインしていない場合でも、「クリックされました」が表示されます。 – Flimm

+0

どのように 'messenger_app_id'を取得するのですか? –

関連する問題