Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook send api - Unable to send a message using user id

When I execute the following request from 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"

I get this error:

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

The documentation states that:

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.

I don't understand where to get the id from. Can someone explain how to obtain the id to use in the API?

like image 795
Amine Daoudi Avatar asked Nov 08 '22 05:11

Amine Daoudi


1 Answers

You get the userID from the webhook when a user messages you. This ID is not the ID of the user, instead every user gets assigned a unique ID when it enters your page. This ID is then used to communicate between your page and the user.

like image 171
Bouke Stam Avatar answered Nov 14 '22 21:11

Bouke Stam