Facebook Graph returns a different id than saved using passport-facebook [duplicate]

1

I have an application where the user logs in using the facebook account, saving the id, name and email. I'm using link Here is the excerpt:

//Cria um usuario do facebook ou vincula a um usuario ja existente
UserSchema.statics.findOrCreateFaceBookUser = function(profile, done) {
    var User = this;
    User.findOne({
        'email': profile.emails[0].value
    }, function(err, user) {
        if (err) {
            throw err;
        }
        if (user) {
            user.facebook = {
                id: profile.id,
                email: profile.emails[0].value,
                name: profile.displayName
            };
            user.save(function(err) {
                if (err) {
                    return next(err);
                } else {
                   // done(null, user);
                }
            });
            done(null, user);
        } else {
            User.findOne({
                'facebook.id': profile.id
            }, function(err, user) {
                if (err) {
                    throw err;
                }
                //if (err) return done(err);
                if (user) {
                    done(null, user);
                } else {
                    User.create({
                        firstName:profile.name.givenName,
                        lastName:profile.name.familyName,
                        email: profile.emails[0].value,
                        gender:profile.gender,
                        image:"http://graph.facebook.com/"+profile.id+"/picture?type=normal",
                        facebook: {
                            id: profile.id,
                            email: profile.emails[0].value,
                            name: profile.displayName
                        }
                    }, function(err, user) {
                        if (err) {
                            throw err;
                        }
                        done(null, user);
                    });
                }
            });
        }

    });


};

The problem is that I need to look for facebook friends who are also using the application, but the id returned by facebook graph does not match what I'm persisting in the application.

link

Any ideas?

    
asked by anonymous 24.05.2014 / 16:25

1 answer

1

Nickolas, was your application created before or after the introduction of API 2.0? Remember that the returned ID is now the app-scoped ID and not the Facebook ID . If so, upgrade your application or call /me/friends using v1.0 or v2.0 as appropriate.

Take a look at link

    
28.05.2014 / 12:58