javascript - Facebook Messenger 复选框插件被 Conceal

标签 javascript jquery html facebook messenger

我正在尝试以一种形式实现新的 Facebook Checkbox 插件,但以一种奇怪的方式我无法在屏幕上显示它。所以我在客户端没有收到错误,但 Iframe 是 Conceal 的。

这是一个简化的代码示例:

<html>
<head>
<script>
    window.fbAsyncInit = function() {
        FB.init({
            appId      : '1815704925309469',
            xfbml      : true,
            version    : 'v2.6'
        });

        FB.Event.subscribe('messenger_checkbox', function(e) {
            console.log("messenger_checkbox event");
            console.log(e);

            if (e.event == 'rendered') {
                console.log("Plugin was rendered");
            } else if (e.event == 'checkbox') {
                var checkboxState = e.state;
                console.log("Checkbox state: " + checkboxState);
            } else if (e.event == 'not_you') {
                console.log("User clicked 'not you'");
            } else if (e.event == 'hidden') {
                console.log("Plugin was hidden");
            }
        });
    };

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

    function confirmOptIn() {
        FB.AppEvents.logEvent('MessengerCheckboxUserConfirmation', null, {
            'app_id':'1815704925309469',
            'page_id':'1711063052543482',
            'ref':'shopping-cart-company',
            'user_ref':'1234'
        });
    }
</script>      

<div class="col-md-7">
    <div class="fb-messenger-checkbox"  
        origin=https://shopping-cart-company.herokuapp.com/index.html
        page_id=1711063052543482
        messenger_app_id=1815704925309469
        user_ref="1234" 
        prechecked="true" 
        allow_login="true" 
        size="large">
    </div>   
</div>

<body>
    <input type="button" onclick="confirmOptIn()" value="Confirm Opt-in"/>
</body>

开发控制台中没有错误。仅记录插件被 Conceal :

Screenshot of dev console message

最佳答案

Facebook 更新了他们的 docs :

The web plugin takes a user_ref parameter which is used as an identifier for the user. When the user finishes the flow, we will pass this identifier back to you to identify the user. This parameter should be unique not just for every user, but for every time the plugin is rendered. If the parameter is not unique, then the plugin may not render.

您必须为复选框插件的每个渲染生成一个新的 user_ref

Checklist显示复选框插件

  • 使用生产应用 ID(不是测试应用 ID)
  • 始终重新生成 user_ref
  • origin 中的域列入白名单
  • origin 中使用正确的协议(protocol) - http/https

关于javascript - Facebook Messenger 复选框插件被 Conceal ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41153714/

相关文章:

在第一次出现的滑出 Div 上触发的 JQuery 函数

javascript - Aurelia 中 View 模型之间的接口(interface)

javascript - 获取对象内的数组数量

javascript - Google 协作平台 HTML 框无法识别 CSS 或 Javascript

javascript - 同步多个 jQuery 属性更新

jquery - Jquery 中的双引号

javascript - 防止从网站保存图像(保存整个页面)

javascript - 服务 promise 返回处理过的数据以实现组件的另一个 promise

javascript - 如何返回在我的 vuejs 组件上更新的数据

javascript - 使用 Greasemonkey 脚本将框架添加到网页底部(并设置其大小)?