Sk Arif
Sk Arif

Reputation: 1120

Specific user info from facebook using passport-facebook

I am using passport-facebook for OAuth and get user information from facebook. But all I am getting is some basic information (i.e. firstname, familyname). I want information like userEmail and friendList.

My current FacebookStrategy is -

passport.use(new FacebookStrategy({
      clientID: configAuth.facebookAuth.appID,
      clientSecret: configAuth.facebookAuth.appSecret,
      callbackURL: configAuth.facebookAuth.callbackUrl
    },
    function(accessToken, refreshToken, profile, done) {
      process.nextTick(function() {
        User.findOne({'facebook.id': profile.id}, function(err, user) {
          if(err)
            return done(err);
          if(user)
            return done(null, user);
          else {
            var newUser = new User;
            console.log(profile);
            newUser.facebook.id = profile.id;
            newUser.facebook.token = accessToken;
            newUser.facebook.name = profile. displayName;
            newUser.save(function(err) {
              if(err)
                throw err;
              return done(null, newUser);
            })
          }
        })
      })
    }
  ));

Can someone tell me how can I get user's email or friend-list. Thanks in advance!!

Upvotes: 3

Views: 207

Answers (1)

recharDS
recharDS

Reputation: 38

If you need email and user_friends you will have to add them to the scope while requesting for facebook-auth. I guess adding following code to yowill help you:

app.get('/auth/facebook', passport.authenticate('facebook', { scope : ['email,user_friends'] }));

Upvotes: 2

Related Questions