使用cURL的Messenger Webhook测试失败

时间:2019-06-02 06:48:58

标签: json facebook curl bots messenger

我正在按照以下指南尝试创建 webhook https://developers.facebook.com/docs/messenger-platform/getting-started/webhook-setup

一切都很好,直到我尝试使用 cmd 发送此 cURL 请求以测试 webhook :-

curl -H "Content-Type: application/json" -X POST "localhost:1337/webhook" -d '{"object": "page", "entry": [{"messaging": [{"message": "TEST_MESSAGE"}]}]}'

应该给我类似的东西:-

  • WEBHOOK_VERIFIED 登录到运行节点进程的命令行。
  • CHALLENGE_ACCEPTED 登录到我发送 cURL 请求的命令行。

相反,在发送 cURL 请求后,我在运行节点过程的命令行中收到此错误:-

SyntaxError: Unexpected token ' in JSON at position 0
    at JSON.parse (<anonymous>)
    at createStrictSyntaxError (C:\Users\Fuad Hasan\Desktop\messenger-webhook\node_modules\body-parser\lib\types\json.js:158:10)
    at parse (C:\Users\Fuad Hasan\Desktop\messenger-webhook\node_modules\body-parser\lib\types\json.js:83:15)
    at C:\Users\Fuad Hasan\Desktop\messenger-webhook\node_modules\body-parser\lib\read.js:121:18
    at invokeCallback (C:\Users\Fuad Hasan\Desktop\messenger-webhook\node_modules\raw-body\index.js:224:16)
    at done (C:\Users\Fuad Hasan\Desktop\messenger-webhook\node_modules\raw-body\index.js:213:7)
    at IncomingMessage.onEnd (C:\Users\Fuad Hasan\Desktop\messenger-webhook\node_modules\raw-body\index.js:273:7)
    at IncomingMessage.emit (events.js:205:15)
    at endReadableNT (_stream_readable.js:1137:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:9)

在运行 cURL 请求的命令行中出现此错误:-

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>SyntaxError: Unexpected token &#39; in JSON at position 0<br> &nbsp; &nbsp;at JSON.parse (&lt;anonymous&gt;)<br> &nbsp; &nbsp;at createStrictSyntaxError (C:\Users\Fuad Hasan\Desktop\messenger-webhook\node_modules\body-parser\lib\types\json.js:158:10)<br> &nbsp; &nbsp;at parse (C:\Users\Fuad Hasan\Desktop\messenger-webhook\node_modules\body-parser\lib\types\json.js:83:15)<br> &nbsp; &nbsp;at C:\Users\Fuad Hasan\Desktop\messenger-webhook\node_modules\body-parser\lib\read.js:121:18<br> &nbsp; &nbsp;at invokeCallback (C:\Users\Fuad Hasan\Desktop\messenger-webhook\node_modules\raw-body\index.js:224:16)<br> &nbsp; &nbsp;at done (C:\Users\Fuad Hasan\Desktop\messenger-webhook\node_modules\raw-body\index.js:213:7)<br> &nbsp; &nbsp;at IncomingMessage.onEnd (C:\Users\Fuad Hasan\Desktop\messenger-webhook\node_modules\raw-body\index.js:273:7)<br> &nbsp; &nbsp;at IncomingMessage.emit (events.js:205:15)<br> &nbsp; &nbsp;at endReadableNT (_stream_readable.js:1137:12)<br> &nbsp; &nbsp;at processTicksAndRejections (internal/process/task_queues.js:84:9)</pre>
</body>
</html>
curl: (6) Could not resolve host: page,
curl: (6) Could not resolve host: entry
curl: (3) [globbing] bad range specification in column 2
curl: (3) [globbing] bad range specification in column 2
curl: (3) [globbing] unmatched close brace/bracket in column 13

为什么会出现此错误?我尝试用Google搜索它,但没有运气。我对JSON文件也不了解,所以请帮帮我。

  

注意:我是这方面的超级初学者,所以请放轻松我吧

0 个答案:

没有答案