Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the name of someone with messenger chat bot? (Facebook Messenger SDK)

Hi I'm very new to coding in PHP and Messenger Bots.

I was wondering how i would access the name of someone who was messaging my chat bot.

like image 377
Hey Avatar asked Oct 20 '25 05:10

Hey


1 Answers

The User Profile API may help you.

use the event.sender.id received from the messenger bot server (/webhook), and follow the request below

curl -X GET "https://graph.facebook.com/v2.6/<USER_ID>?fields=first_name,last_name,profile_pic,locale,timezone,gender&access_token=<PAGE_ACCESS_TOKEN>"

then you could get the returned json below

{
     "first_name": "Peter",
     "last_name": "Chang",
     "profile_pic": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpf1/v/t1.0-1/p200x200/13055603_10105219398495383_8237637584159975445_n.jpg?oh=1d241d4b6d4dac50eaf9bb73288ea192&oe=57AF5C03&__gda__=1470213755_ab17c8c8e3a0a447fed3f272fa2179ce",
     "locale": "en_US",
     "timezone": -7,
     "gender": "male"
}
like image 61
iownthegame Avatar answered Oct 21 '25 20:10

iownthegame