使用护照模块获取Facebook个人资料活动

时间:2015-06-10 21:04:13

标签: node.js facebook-graph-api passport-facebook

我试图让未来的活动用户参加使用护照模块,但我明显遗漏了一些东西。我按照Facebook API获得了我需要的权限:

    router.get('/auth/facebook', passport.authenticate('facebook', { scope: [ 'public_profile', 'user_events' ] }));
    router.get('/auth/facebook/callback', passport.authenticate('facebook', {
        successRedirect:'/welcome',
        failureRedirect:'/'
    }))

但是当我试图打印这样的事件时:

 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

我尝试将name替换为value,因为它与照片完美配合,我尝试了许多其他方法,但我根本无法让这个工作。请帮忙吗?

0 个答案:

没有答案