Frage

Ich kann grundlegende Benutzerinformationen über Passport-Facebook abrufen, nach dem untenstehenden Code und Speichern in MONGODB:

generasacodicetagpre.

Ich kann das Profilbild jedoch nicht im "Profil" sehen.

Die Dokumentation https://github.com/jaredhanson/passport-facebook sagt, um Fotos abzurufen, die wir müssendie profilefields wie unten.Aber ich kann die Foto-URL sehen, aber verlieren Sie andere Daten, die in _JSON, z.profil._json.lage.name.Wie kann ich ein Foto mit anderen Benutzerinformationen abrufen?

generasacodicetagpre.

War es hilfreich?

Lösung 3

Yes, the picture can be accessed via the graph api using the access token like this. "graph.facebook.com/"; + profile.username + "/picture" + "?width=200&height=200" + "&access_token=" + accessToken; There is no need to use the profile fields.

Andere Tipps

Wenn Sie ein größeres Bild benötigen (Standard in MIKSII-Beispiel oben ist 50px x 50px, der ziemlich klein ist), dann verwenden Sie:

generasacodicetagpre.

und dann

generasacodicetagpre.

Dies gibt ein 200px x 200px-Profilbild für diesen Benutzer zurück.

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.

As this answer, it will be work better with this code.

passport.use(new FacebookStrategy({
  clientID: FACEBOOK_APP_ID,
  clientSecret: FACEBOOK_APP_SECRET,
  callbackURL: FACEBOOK_APP_CALLBACK,
  profileFields: ['id', 'displayName', 'picture.type(large)', 'email', 'birthday', 'friends', 'first_name', 'last_name', 'middle_name', 'gender', 'link']
}, (accessToken, refreshToken, profile, cb) => {
  const picture = `https://graph.facebook.com/${profile.id}/picture?width=200&height=200&access_token=${accessToken}`
  //
}))
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top