Closed alyssayc closed 8 years ago
It is because the Messenger platform creates a page-scoped id
for each user for every page/bot they message (i.e. each user has a different id for each page).
sender.id
or in Botkit's case fb_id
is not a Facebook user id.
Check this documentation by Facebook.
This is my code for the same.
var senderId = message.user
getName: function(senderId) {
request.get({
headers: { 'content-type': 'application/x-www-form-urlencoded' },
url: "https://graph.facebook.com/v2.6/" + senderId + "?fields=first_name&access_token=" +PAGE_TOKEN,
}, function(err, response, body) {
if (err) {
return err
}
var name = JSON.parse(body).first_name
});
}
@alyssayc did that resolve your question?
@webtaculars Hmm not sure how can I match this info. For example in my wordpress instance I use social login I'm saving the app_scoped_id of the user. How can I determine if the chatbot user is the same person? I tried the userprofile trick but couldn't figure it out https://chatbotsmagazine.com/fb-messenger-bot-how-to-identify-a-user-via-page-app-scoped-user-ids-f95b807b7e46#.tb2fvatrj in this request https://graph.facebook.com/v2.6/me?fields=picture&access_token=
The info here is pretty misleading because you can simply get the full user name from message.address.user.name
without making any API calls.
You can't match this info because Facebook has (recently) designed the API such that the id of the user messaging your bot is not the same as the facebook id of that user. I.e. this identifier that you receive is only useful for identifying users interacting with your bot. If you need to access the actual facebook profile and other information, you would need to use FB's graph API instead.
Is there a way of getting the Facebook id ? if yes how can I do so ?
@aidonsnous no, there isn't
Hi, I am trying to use the facebook user id to get additional user information, but the user id returned from message.user is not the the correct id for that user.