Retrieving photo from Facebook using passport-facebook

前端 未结 5 1893
醉梦人生
醉梦人生 2021-02-13 02:44

I am able to retrieve basic user information via passport-facebook, following the below code and saving in mongodb:

app.get(\"/auth/facebook\", passport.authenti         


        
5条回答
  •  忘了有多久
    2021-02-13 03:06

    In addition to answer of your question - you don't have to do it that way. As you mentioned you can define the required attributes for Facebook profile:

      clientID: "...",
      clientSecret: "...",
      callbackURL: "...",
      profileFields: ['id', 'displayName', 'name', 'gender', ..., 'photos']
    

    What than you can do is just simply grab the value of the given attribute. Let's say you want to make an attribute that will hold this value:

    picture: profile.photos ? profile.photos[0].value : '/img/faces/unknown-user-pic.jpg'
    

    This proved to be a better solution since some users or sometimes the value of username may be undefined.

    I hope you find this useful too,

    Thank you.

提交回复
热议问题