首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用cordova-4从Facebook检索名称

使用cordova-4从Facebook检索名称
EN

Stack Overflow用户
提问于 2017-02-14 18:54:50
回答 1查看 121关注 0票数 0

用户注册成功后,我需要从Facebook检索姓名。

实际上我有:

代码语言:javascript
复制
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进行注册流,然后在防火墙中注册。但我需要从facebook获得这些用户属性,以便单独存储这些信息。

谢谢已经提前了!伊万。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-15 03:02:10

请参阅此处的完整项目https://github.com/aaronksaunders/AngularFire2-Ionic2-Facebook

代码语言:javascript
复制
/**
   * 
   * 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);
        });
    });
  }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42234069

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档