howdyai / botkit

Botkit is an open source developer tool for building chat bots, apps and custom integrations for major messaging platforms.
MIT License
11.48k stars 2.28k forks source link

message.user is not the actual facebook id #325

Closed alyssayc closed 8 years ago

alyssayc commented 8 years ago

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.

krismuniz commented 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.

webtaculars commented 8 years ago

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
    });
  }
peterswimm commented 8 years ago

@alyssayc did that resolve your question?

cAstraea commented 7 years ago

@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= what is the APP_USER_ACCES_TOKEN

anton-bot commented 6 years ago

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.

ongzexuan commented 6 years ago

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.

aidonsnous commented 5 years ago

Is there a way of getting the Facebook id ? if yes how can I do so ?

anton-bot commented 5 years ago

@aidonsnous no, there isn't