استرجاع الصورة من الفيسبوك باستخدام جواز السفر الفيسبوك
-
21-12-2019 - |
سؤال
أنا قادر على استرداد معلومات المستخدم الأساسية عبر Passport Facebook، بعد التعليمات البرمجية أدناه والادخار في MongoDB:
giveacodicetagpre.ومع ذلك، لا أستطيع رؤية صورة الملف الشخصي في "الملف الشخصي".
الوثائق https://github.com/jaredhanson/passport-facebook يقول لاسترداد الصور التي نحتاجها لتمرير الصورالملفات الشخصية أدناه.ولكن القيام بذلك، أنا قادر على رؤية عنوان URL للصور ولكن فقد فقدان البيانات الأخرى التي كانت موجودة في _json .g.الملف الشخصي ._json.location.name.كيف يمكنني استرداد الصورة مع معلومات المستخدم الأخرى سليمة؟
giveacodicetagpre.المحلول 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.
نصائح أخرى
إذا كنت بحاجة إلى صورة أكبر (الافتراضي في مثال Miksii أعلاه هو 50PX X 50PX وهو صغير جدا)، ثم استخدم:
giveacodicetagpre.ثم
giveacodicetagpre.سيعود هذا صورة ملف تعريف 200PX X 200PX لهذا المستخدم.
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}`
//
}))