发送到Messenger的按钮没有显示

时间:2018-07-05 01:54:16

标签: facebook facebook-messenger

我想将Send To Messenger按钮集成到我的Web应用程序中。问题出在 localhost 环境中,按钮可以渲染,但是在登台环境中,按钮没有渲染。 (即使两个环境使用相同的page_idmessenger_app_id

这是“发送到Messenger”按钮的代码:

<div
class="fb-send-to-messenger"
page_id="568015096933xxx"
messenger_app_id="402876686862xxx"
color="blue"
size="xlarge"
data-ref="123456"
cta_text="SUBSCRIBE_TO_UPDATES"></div>

注意:我确实将登台网站的域添加到了Facebook页面的白名单网站中。

1 个答案:

答案 0 :(得分:0)

这是我解决此问题的“肮脏”方法...基本上,我复制了HTML of rendered button并从中构建了一个组件。

import { Meteor } from 'meteor/meteor';
import React from 'react';
import { LANGUAGE } from '/imports/constants';
import { compose, withProps, withHandlers } from 'recompose';

const SendToMessengerEnhancer = compose(
  withProps(() => {
    const user = Meteor.user();
    const language = (user.language === LANGUAGE.EN || user.language === LANGUAGE['EN-US']) ? 'en_US' : 'vi_VN';
    const { appId, pageId } = Meteor.settings.public.facebook;
    const ctaText = 'SUBSCRIBE_TO_UPDATES';
    const color = 'blue';
    const size = 'xlarge';
    return {
      language,
      appId,
      pageId,
      ctaText,
      userId: Meteor.userId(),
      color,
      size,
    };
  }),
  withHandlers({
    createMarkup: ({
      language,
      appId,
      pageId,
      ctaText,
      userId,
      color,
      size,
    }) => () => {
      const originEncoded = encodeURIComponent(Meteor.absoluteUrl());
      const domain = window.location.hostname;
      const channel = `http://staticxx.facebook.com/connect/xd_arbiter/r/xaOI6zd9HW9.js?version=42#cb=fab5aacb255238&domain=${domain}&origin=${originEncoded}f1c42e700a608a4&relation=parent.parent`;
      const channelEncoded = encodeURIComponent(channel);
      const html = `
      <div
        class="fb-send-to-messenger fb_iframe_widget"
        page_id="${pageId}"
        messenger_app_id="${appId}"
        color="${color}"
        size="${size}"
        enforce_login="false"
        data-ref="${userId}"
        cta_text="${ctaText}"
        fb-xfbml-state="rendered"
        fb-iframe-plugin-query="app_id=&amp;color=blue&amp;container_width=532&amp;cta_text=${ctaText}&amp;enforce_login=false&amp;locale=${language}&amp;messenger_app_id=${appId}&amp;page_id=${pageId}&amp;ref=${userId}&amp;sdk=joey&amp;size=${size}">
          <span
            style="vertical-align: bottom; width: 256px; height: 68px;">
            <iframe
              name="f3769e54c3c93e8"
              width="1000px"
              height="1000px"
              frameborder="0"
              allowtransparency="true"
              allowfullscreen="true"
              scrolling="no"
              allow="encrypted-media"
              title="fb:send_to_messenger Facebook Social Plugin"
              src="https://www.facebook.com/v2.12/plugins/send_to_messenger.php?app_id=&amp;channel=${channelEncoded}&amp;color=${color}&amp;container_width=532&amp;cta_text=${ctaText}&amp;enforce_login=false&amp;locale=${language}&amp;messenger_app_id=${appId}&amp;page_id=${pageId}&amp;ref=${userId}&amp;sdk=joey&amp;size=${size}"
              style="border: none; visibility: visible; width: 256px; height: 68px;"
              class=""
            ></iframe>
          </span>
        </div>
      `;
      return {
        __html: html,
      };
    },
  }),
);

const SendToMessengerView = ({ createMarkup }) => <div className="send-to-messenger-btn" dangerouslySetInnerHTML={createMarkup()} />;

export default SendToMessengerEnhancer(SendToMessengerView);

一些注意事项:

  • 我的应用基于Meteor构建,这就是为什么您会看到Meteor.settingsMeteor.user()
  • 的原因
  • 我使用recompose来帮助建立HOC

希望这对遇到相同问题的其他人有所帮助。