php - Facebook 发送 api - 无法使用用户 ID 发送消息

标签 php facebook api facebook-graph-api curl

当我从 https://developers.facebook.com/docs/messenger-platform/send-api-reference 执行以下请求时

curl -X POST -H "Content-Type: application/json" -d '{
  "recipient":{
    "id":"USER_ID"
  },
  "message":{
    "text":"hello, world!"
  }
}' "https://graph.facebook.com/v2.6/me/messages?access_token=PAGE_ACCESS_TOKEN"

我收到这个错误:

Graph returned an error: (#100) Parameter recipient[id]: Invalid id: "the id of the recipient"

文档指出:

The id must be an ID that was retrieved through the Messenger entry points or through the Messenger webhooks (e.g., a person may discover your business in Messenger and start a conversation from there. These IDs are page-scoped IDs (PSID). This means that the IDs are unique for a given page. If you have an existing Facebook Login integration, user IDs are app-scoped and will not work with the Messenger platform.

我不知道从哪里得到 id。有人可以解释如何获取要在 API 中使用的 ID 吗?

最佳答案

当用户向您发送消息时,您可以从 webhook 获取用户 ID。此 ID 不是用户的 ID,而是每个用户在进入您的页面时都会被分配一个唯一的 ID。然后使用此 ID 在您的页面和用户之间进行通信。

关于php - Facebook 发送 api - 无法使用用户 ID 发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40679927/

相关文章:

php - 未使用的 mysql 连接会减慢脚本速度吗?

php - 如何获取mysql数据库表上次更新的确切日期和时间?

php - 如何在 Laravel 5.1 Integrity constraint violation : 1452? 中添加外键

php - 是否有用于处理单位和数量的 PHP 库/类?

ruby-on-rails - 如何从外部网站重新创建图像预览?

facebook - 按键值搜索不可变映射

java - 如何获取软层操作系统引用代码列表?

php - Facebook API : show dialog window for the user select page (manage_pages extendend perm)

javascript - 刷新网页时保持缩放

Facebook 工作场所合规性集成 - 错误代码 960