1

这是我在 node.js 中的第一步,尤其是在护照中,我遇到了一个非常烦人的问题。我正在尝试让用户使用他的 Facebook 个人资料参加的活动,但无论我尝试什么,它都不起作用。所以我想“好吧,让我们获取其他数据”,但除了基本的显示名称和个人资料图片之外,任何其他尝试(生日、事件、朋友列表等)最终都没有数据。我在过去几天(第一次)尝试了很多使用 Facebook 的 api 并且根本无法弄清楚......这是我最后一次尝试:

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,
                //friends:profile.user.friends[0],
                profileUrl:profile.profileUrl

            });


            newFbUSer.save(function(err){
                done(null,newFbUSer);
                console.log(newFbUSer.displayName);
            })
        }
    })
}))  

关于如何获取和使用用户的朋友列表/事件的任何帮助?

4

2 回答 2

0

也许您在调用 Facebook 登录时尚未将所需信息的详细信息传递给 facebook。在调用 facebook 登录时,您需要指定范围内需要的所有信息。例如,如果您需要 public_profile、email、user_friends 以下是您将添加到路由中的代码:

app.get('/auth/facebook', passport.authenticate('facebook', { scope : 'public_profile,email,user_friends' }));
于 2016-02-09T07:43:03.653 回答
0

试试这个全名:

fullName: profile.name.givenName + ' ' + profile.name.familyName
于 2016-03-30T23:28:03.630 回答