Node.js 使用passport模块获取facebook个人资料事件
我试图让用户使用passport模块参加未来的活动,但我显然遗漏了一些东西。我遵循Facebook API并获得了所需的许可,如下所示:Node.js 使用passport模块获取facebook个人资料事件,node.js,facebook-graph-api,passport-facebook,Node.js,Facebook Graph Api,Passport Facebook,我试图让用户使用passport模块参加未来的活动,但我显然遗漏了一些东西。我遵循Facebook API并获得了所需的许可,如下所示: router.get('/auth/facebook', passport.authenticate('facebook', { scope: [ 'public_profile', 'user_events' ] })); router.get('/auth/facebook/callback', passport.authenticate(
router.get('/auth/facebook', passport.authenticate('facebook', { scope: [ 'public_profile', 'user_events' ] }));
router.get('/auth/facebook/callback', passport.authenticate('facebook', {
successRedirect:'/welcome',
failureRedirect:'/'
}))
events:profile.events[0].name,
^
TypeError: Cannot read property '0' of undefined
但当我试图打印这样的事件时:
passport.use(new FacebookStrategy({
clientID: config.fb.appID,
clientSecret: config.fb.appSecret,
callbackURL: config.fb.callbackURL,
profileFields: ['id', 'displayName', 'photos', 'birthday', 'events', 'profileUrl', 'emails', 'likes']
}, function(accessToken, refershToken, profile, done){
//Check if the user exists in our Mongo DB database
//if not, create one and return the profile
//if exists, return profile
userModel.findOne({'profileID':profile.id}, function(err, result){
if(result){
done(null,result);
} else {
// Create a new user in our mongoLab account
var newFbUSer = new userModel({
profileID: profile.id,
fullname: profile.displayName,
profilePic:profile.photos[0].value || '',
birthday:profile.birthday,
events:profile.events[0].name,
profileUrl:profile.profileUrl,
});
console.log(newFbUSer.profilePic);
newFbUSer.save(function(err){
done(null,newFbUSer);
})
}
})
events:profile.events[0].name,
^
TypeError: Cannot read property '0' of undefined
我得到这个错误:
events:profile.events[0].name,
^
TypeError: Cannot read property '0' of undefined
我试图用value
替换name
,因为它可以很好地处理照片,我还尝试了许多其他方法,但我就是无法让这一种工作……有什么帮助吗
events:profile.events[0].name,
^
TypeError: Cannot read property '0' of undefined