2017-02-14 5 views
0

ユーザー登録successfulyの後、Facebookから姓と名を取得する必要があります。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のユーザー属性を取得して、この情報を別々に保存する必要があります。

ありがとうございます! Ivan。

答えて

1

これを実行しようとする前に、ここで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); 
     }); 
    }); 
    } 
+0

完全なプロジェクトを参照してください、私はあなたに相談したい:あなたがリポジトリREADMEに言及し、このコマンドを何? $ Ionic state restore –

+0

すべてのプラグインを保存している場合、状態復元を実行すると、最初にインストールしたときに使用した関連変数がすべてインストールされます –

+0

ありがとう、ありがとうございます!それは動作し、私の問題を解決:) –

関連する問題