Tareq Ahamed
Tareq Ahamed

Reputation: 19

facebook id return by passportjs doesn't match with facebook user id

I used passportjs facebook strategy, to fetch user information. But the user id return by passportjs doesn't match with actual facebook user id and facebook username is undefined. How to fetch actual facebook user id and username?

passport.use(new FacebookStrategy({
        clientID: config.get('facebook.clientID'),
        clientSecret: config.get('facebook.clientSecret'),
        callbackURL: config.get('facebook.callbackURL'),
        passReqToCallback: true,
        // profileFields: ['id', 'email', 'first_name', 'last_name']
    },
    function(req, accessToken, refreshToken, profile, done) {
        console.log(profile);...........
........................................

//output of console.log(profile)

_json:Object {name: "Tareq Ahamed", id: "1720360918026935"} _raw:"{"name":"Tareq Ahamed","id":"1720360918026935"}" displayName:"Tareq Ahamed" gender:undefined id:"1720360918026935" name:Object {familyName: undefined, givenName: undefined, middleName: undefined} profileUrl:undefined provider:"facebook" username:undefined

// but the actual facebook user id is 100001591295237

Upvotes: 0

Views: 143

Answers (1)

andyrandy
andyrandy

Reputation: 74004

There is no way to get the "real" ID of a user, or his username. You do not need them anyway, you can identify returning users with the ID you get - it´s called "App Scoped ID" and it will stay the same per App.

If you want additional data in a request and not just id and name, you have to use the fields parameter as documented: https://developers.facebook.com/docs/graph-api/using-graph-api#fields

Upvotes: 1

Related Questions