Get the Sender’s Name and Gender in Facebook Graph API

Get the Sender’s Name and Gender in Facebook Graph API

How can I return the senders first name, last name, and gender from the Facebook Graph API when a message is received?

We need two required parameters such the sender id and a page access token. The sender id can be parsed when a message is received while the page access token can be obtained when you link your page to your Facebook app.

Send a get request to the following replacing the variables with the actual values:

https://graph.facebook.com/v2.11/{ID}?fields={FIELDS_TO_ACCESS_HERE}&access_token={PAGE_ACCESS_TOKEN}

I used Postman to make the GET request and which gives a pretty-printed response of the JSON object.

Return Sender Name and Gender in Facebook Graph API using Postman

Another way is by making a CURL request which gives just the same result.

Return Sender Name and Gender in Facebook Graph API using CURL

You can then use the sender’s details to personalize your response in messenger.

Cromwell Bayon

He is a self-tutored programmer and a Full-Stack Developer. He strives to excel in the newest technology as possible. He has a very high sense of technicality and analytical skills which allows him to resolve any kind of issues related to technology. He also loves woodworking. Read more about him here...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.