当我从 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/