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

时间:2016-11-18 14:48:52

标签: 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"

文件说明:

  

id必须是通过Messenger入口点或Messenger webhooks检索到的ID(例如,某人可能会在Messenger中发现您的业务并从那里开始对话。这些ID是页面范围的ID(PSID)这意味着ID对于给定页面是唯一的。如果您有现有的Facebook登录集成,则用户ID是应用范围的,不适用于Messenger平台。

我不明白从哪里获取id。有人可以解释如何获取在API中使用的id吗?

1 个答案:

答案 0 :(得分:1)

当用户向您发送消息时,您将从webhook获取userID。此ID不是用户的ID,而是在每个用户进入您的页面时为其分配唯一ID。然后,此ID用于在您的页面和用户之间进行通信。