如何在我的应用程序中使用Facebooklogin

api / users.js

var fb = { clientID: 'xxxxxxxxxxxxxxxx', clientSecret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', callbackURL: 'http://localhost:4268/auth/facebook/callback' }; var fbCallback = function(accessToken, refreshToken, profile, cb) { console.log(accessToken, refreshToken, profile); }; passport.use(new FacebookStrategy(fb, fbCallback)); router.get('/', passport.authenticate('facebook', {scope:"email"})); router.get('/auth/facebook/callback',function(req, res) { res.send("logged in"); }); 

我已经把这个代码放在名为users.js的文件夹api ,当我做Facebooklogin时,我使用的是localhost:4268/api/user/ 。 login后,我期待消息“login”,但它不是。 callbackurl中是否有任何错误?

更改

  var fb = { clientID: 'xxxxxxxxxxxxxxxx', clientSecret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', callbackURL: 'http://localhost:4268/auth/facebook/callback' }; var fbCallback = function(accessToken, refreshToken, profile, cb) { console.log(accessToken, refreshToken, profile); }; 

  var fb = { clientID: 'xxxxxxxxxxxxxxxx', clientSecret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', callbackURL: 'http://localhost:4268/auth/facebook/callback', profileFields:['id','displayName','emails'] }; var fbCallBack = function(accessToken, refreshToken, profile, done) { console.log(profile); var me = new user({ email:profile.emails[0].value, name:profile.displayName }); /* save if new */ user.findOne({email:me.email}, function(err, u) { if(!u) { me.save(function(err, me) { if(err) return done(err); done(null,me); }); } else { console.log(u); done(null, u); } });