我正在尝试从用户的Facebook页面获取数据,这些数据在我的应用程序中使用Facebook登录/注册,如生日,图像,性别等。现在我只是将任意值添加到我的数据库但我想得到他们的性别,个人资料图片网址和生日(如果可能)。对于我的生活,我无法弄清楚如何去做。这是我到目前为止所做的:
loginWithFacebook() {
return Observable.create(observer => {
if (this.platform.is('cordova')) {
Facebook.login(['public_profile', 'email']).then(facebookData => {
console.log(facebookData);
let provider = firebase.auth.FacebookAuthProvider.credential(facebookData.authResponse.accessToken);
firebase.auth().signInWithCredential(provider).then(firebaseData => {
this.af.database.list('users').update(firebaseData.uid, {
name: firebaseData.displayName,
email: firebaseData.email,
provider: 'facebook',
keys: firebaseData.keys,
birthday: firebaseData.birthday,
snapchat: firebaseData.snapchat,
gender: firebaseData.gender,
image: firebaseData.photoURL
});
observer.next();
});
}, error => {
observer.error(error);
});
} else {
this.af.auth.login({
provider: AuthProviders.Facebook,
method: AuthMethods.Popup,
}).then((facebookData) => {
console.log(facebookData);
this.af.database.list('users').update(facebookData.auth.uid, {
name: facebookData.auth.displayName,
email: facebookData.auth.email,
provider: 'facebook',
keys: 5,
birthday: 'w',
snapchat: 'w',
gender: 'male',
image: facebookData.auth.photoURL
});
observer.next();
}).catch((error) => {
console.info("error", error);
observer.error(error);
});
}
});
}
答案 0 :(得分:1)
Firebase不支持此功能。您必须使用Facebook访问令牌对Facebook进行额外的api调用以获取该数据(确保在获取该访问令牌时提示所需的范围)。
AJAX GET 'https://graph.facebook.com/me?access_token=' + credential.accessToken