我想将Facebook客户聊天插件集成到React Web应用程序中。
应用程序在以下网址上以开发模式运行: http:// localhost:3000 /
使用的npm软件包: react-messenger-customer-chat
用相同的名称创建了一个新的Facebook App和Facebook Site,并在Facebook中为开发人员建立了联系。
在React端存储了 App ID 和 Page ID 。
添加到设置->基本-> 应用程序域:localhost (在“ http:// localhost:3000 /中键入,但另存为” localhost”
添加了新平台-> 网站:http:// localhost:3000 /
已在Messenger平台上列入白名单->高级设置-> 已列入白名单的域:http://127.0.0.1:3000/,https://127.0.0.1:3000/,https://127.0.0.1:3000/,https://127.0.0.1/
设置React代码,将参数传递给新组件。重新加载后,我收到了来自Facebook的200条响应,但是网站上显示了一个空的div,并且我无法使其正常工作(甚至尝试使用纯Javascript脚本或创建了Test App)。
在App.js中使用:
import React from 'react';
import MessengerCustomerChat from 'react-messenger-customer-chat';
import { FACEBOOK_APP_ID, FACEBOOK_PAGE_ID } from '../../shared/configuration';
const Chat = (props) => (
<div>
<MessengerCustomerChat pageId={FACEBOOK_PAGE_ID} appId={FACEBOOK_APP_ID} />
</div>
);
export default Chat;
请求网址:
https://www.facebook.com/v2.11/plugins/customerchat.php?app_id=<MY_APP_APP_ID>&channel=https%3A%2F%2Fstaticxx.facebook.com%2Fx%2Fconnect%2Fxd_arbiter%2F%3Fversion%3D46%23cb%3Df197f00e47470a%26domain%3Dlocalhost%26origin%3Dhttp%253A%252F%252Flocalhost%253A3000%252Ff229f87298f7008%26relation%3Dparent.parent&container_width=0&locale=en_US&page_id=MY_APP_PAGE_ID>&request_time=1603379771509&sdk=joey
响应标题:
alt-svc: h3-29=":443"; ma=3600,h3-27=":443"; ma=3600
cache-control: private, no-cache, no-store, must-revalidate
content-encoding: br
content-security-policy: default-src * data: blob: 'self';script-src *.facebook.com *.fbcdn.net *.facebook.net *.google-analytics.com *.virtualearth.net *.google.com 127.0.0.1:* *.spotilocal.com:* 'unsafe-inline' 'unsafe-eval' blob: data: 'self';style-src data: blob: 'unsafe-inline' *;connect-src *.facebook.com facebook.com *.fbcdn.net *.facebook.net *.spotilocal.com:* wss://*.facebook.com:* https://fb.scanandcleanlocal.com:* attachment.fbsbx.com ws://localhost:* blob: *.cdninstagram.com 'self' chrome-extension://boadgeojelhgndaghljhdicfkmllpafd chrome-extension://dliochdbjfkdbacpmhlcpmleaejidimm;block-all-mixed-content;upgrade-insecure-requests;
content-security-policy: frame-ancestors https://www.facebook.com;
content-type: text/html; charset="utf-8"
date: Thu, 22 Oct 2020 15:16:11 GMT
expires: Sat, 01 Jan 2000 00:00:00 GMT
facebook-api-version: v8.0
pragma: no-cache
status: 200
strict-transport-security: max-age=15552000; preload
vary: Accept-Encoding
x-content-type-options: nosniff
x-fb-debug: 3hcF+KdxLlfSCdNr3qJFo24n/o8y1GyMJRbFbyeBdoZdhniyI8ummvUQAGY6KB8GAdDePynl83js0QmsH6a5xA==
x-xss-protection: 0
HTML代码(第一个“ div”应为“聊天”组件内容,其他两行由npm包注入):
该问题的解决方案是什么?
答案 0 :(得分:1)
使用Facebook聊天插件开发和测试React应用程序时,不能使用域名“ localhost”。