I want send message as shown link https://developers.facebook.com/docs/messenger-platform/send-api-reference#rate_limit You can see parameter "USER_ID". How to get page scoped user id? please show screenshot and provide detailed answer.
Currently, there is no official method to connect user_id and page_scoped_id in both ways. You can hack it by picture_url because both URLs are same. see https://chatbotsmagazine.com/fb-messenger-bot-how-to-identify-a-user-via-page-app-scoped-user-ids-f95b807b7e46#.kcae9367y
As the documentation say higher up on the same page:
The recipient.id must be an id that was retrieved through the Messenger entry points or through the Messenger callbacks (e.g., a person may discover your business in Messenger and start a conversation from there.
These ids are page-scoped ids. 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 found no really & efficiently helpful information regarding this.
So I came up and tried to crack this. and finally gotcha!
to find PSID
page-scoped-id
for the user, you need to set up a messenger webhook or play with Graph Explorer. I used Graph Explorer for this purpose.
In Graph Explorer choose the page/app and then also select the required permissions related to messaging and managing pages etc.
then first you'll have to use the graph conversations
API page-id/conversations
it will load the conversations with pagination. choose your target and then again you need to make another request with the conversation id /t_2117846685221333?fields=id,name,participants
. this way it will list the conversations with PSID Page-Scoped-ID
the id
data is your PSID
.
Hope this helps!
As stated in official document: https://developers.facebook.com/docs/messenger-platform/get-started. You will need the following method with parameter "participants":
For curl:
curl -i -X GET "https://graph.facebook.com/LATEST-API-VERSION/PAGE-ID/conversations?fields=participants&access_token=PAGE-ACCESS-TOKEN"
For Python:
import requests
page_id = '<your_page_id>'
page_access_token = '<your_page_access_token>'
# get PSID
response = requests.get(
f'https://graph.facebook.com/{page_id}/conversations?fields=participants&access_token={page_access_token}')
print(response.text)
But before you get page_access_token. You will need to access Graph Explorer to assign permission and get token as stated in here: https://developers.facebook.com/docs/marketing-apis/overview/authentication/
© 2022 - 2024 — McMap. All rights reserved.