簡體   English   中英

使用cordova-plugin-facebook4從Facebook檢索名稱

[英]Retrieve name from Facebook using cordova-plugin-facebook4

用戶注冊成功后,我需要從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獲得那些用戶屬性,以分別存儲此信息。

提前致謝! 伊萬

在這里查看完整的項目https://github.com/aaronksaunders/AngularFire2-Ionic2-Facebook

/**
   * 
   * 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);
        });
    });
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM