how to get fb page scoped user id for sending message
Asked Answered
D

4

8

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.

Demaggio answered 27/5, 2016 at 12:11 Comment(0)
F
4

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

Ftlb answered 20/8, 2016 at 7:4 Comment(0)
P
3

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.

Periphrasis answered 27/5, 2016 at 16:7 Comment(9)
What do you do with all your app-scoped data when you setup the messenger integration ? Do you have to maintain two entirely different datasets that live in different worlds or can you join them somehow ?Dude
What do you mean with when you set up?Periphrasis
Say, I have a working login integration with an app. Now, I update the app to a new version that requests for messenger permissions and get a couple of users to upgrade. I now get both the standard graph api notifications and the messenger api notifications on the same rtu/webhook endpoint. Is there a way to join the page-scoped user ids I get from the messenger notifications with the app-scoped user ids I get from the normal graph api notifications ?Dude
I have read before but did not understand how to do it. I use microsoft bot framework and webhook url not mine so I do not understand what to send to receive USER_ID facebook.botframework.com/api/v1/bots/…Demaggio
Facebook will send you the page-scoped user id. After you get one you use thatPeriphrasis
sorry, what is that? my url? please provide detailed exampleDemaggio
When the user message your app you will get a page-scoped user id. Then you use that id to replyPeriphrasis
developers.facebook.com/tools/explorer/… what is it?Demaggio
Nothing to do with what you want to doPeriphrasis
B
2

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 enter image description here

the id data is your PSID.

Hope this helps!

Barrister answered 8/12, 2023 at 6:56 Comment(0)
S
0

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/

Serafina answered 24/7, 2022 at 16:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.