使用cordova-plugin-facebook4

时间:2017-02-14 18:54:50

标签: android facebook angular ionic2 cordova-plugins

我需要在用户注册成功后从Facebook检索名字和姓氏。

其实我有:

Facebook
            .login(['email'])
            .then( (response) => {
               /*
              Here i need to get name and last name for later usage
              */
                let facebookCredential = firebase.auth.FacebookAuthProvider
                    .credential(response.authResponse.accessToken);

                firebase.auth().signInWithCredential(facebookCredential)
                    .then((success) => {
                        this.userProfile = success;

                        this.storage.set('facebookMethod_email', this.userProfile.email);

                        this.nav.setRoot(HomePage,
                            {
                            facebookUser: this.userProfile
                            },
                            {
                                animate: true,
                                direction: 'forward'
                            });
                    })
                    .catch((error) => {
                        let prompt = this.alertCtrl.create({
                        title: this.FAIL_TITLE,
                        subTitle: this.AUTH_FAILED_SUBTITLE,
                        buttons: [this.ACCEPT_BUTTON]
                        });
                    prompt.present();
                    });
            })
            .catch((error) => {
                console.log(error)
            });

它完美无缺。它首先使用facebook进行注册流程,然后在firebase中注册。但我需要从Facebook获取这些用户attributtes以单独存储此信息。

提前感谢! 伊凡。

1 个答案:

答案 0 :(得分:1)

在此处查看完整项目acquireToken

/**
   * 
   * get the profile information from the Facebook user to add it to the database
   * 
   * @returns
   * 
   * @memberOf HomePage
   */
  _FBUserProfile() {

    return new Promise((resolve, reject) => {
      Facebook.api('me?fields=id,name,email,first_name,last_name,picture.width(100).height(100).as(picture_small),picture.width(720).height(720).as(picture_large)', [])
        .then((profileData) => {
          console.log(JSON.stringify(profileData));
          return resolve(profileData);
        }, (err) => {
          console.log(JSON.stringify(err));
          return reject(err);
        });
    });
  }