簡體   English   中英

客戶聊天不適用於 React Messenger 客戶聊天

[英]Customer chat not working with React Messenger Customer Chat

我想將 Facebook 客戶聊天插件集成到 React Web 應用程序中。

應用程序在 URL 上以開發模式運行: http://localhost:3000/

使用 npm 包: react-messenger-customer-chat

創建了一個同名的新 Facebook 應用程序和 Facebook 站點,並將它們連接到 Facebook for Developers。

在 React 端存儲App IDPage 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 腳本或創建了一個測試應用程序)。

在 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'應該是'Chat'組件內容,其他兩行由npm包注入): 在此處輸入圖片說明

這個問題的解決方案是什么?

在使用 Facebook 聊天插件開發和測試 React 應用程序時,域名為“localhost”不是一個選項。

  1. 在操作系統hosts文件中要添加一個新條目,例如: 127.0.0.1 react-with-chat-app.com
  2. 在 Windows 上,使用ipconfig /flushdns命令以管理員身份運行命令提示符。
  3. 在 React 項目的根目錄中添加.env文件,並添加您的新主機名: HOST=react-with-chat-app.com
  4. http://react-with-chat.com/添加到 Facebook 站點白名單域數組,並將 Facebook 應用程序的網站也更改為http://react-with-chat.com/
  5. 重啟 React 應用程序,使用: http ://react-with-chat-app.com:3000 訪問,並測試聊天功能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM