【问题标题】:IONIC 2 RefrenceError: firebase is not definedIONIC 2 RefrenceError:firebase 未定义
【发布时间】:2017-02-15 13:06:49
【问题描述】:

我已经为此烦恼了很长一段时间了。

我正在尝试使用 Facebook Auth for Firebase。我还在 app.module.ts 中初始化了我的应用程序 但是当我在我的 Android 设备上运行下面提到的代码时,我得到了

"RefrenceError: firebase 未定义"

  signInWithFacebook(){
    var _authInfo

Facebook.login(['email'])
  .then((_response) => {
    console.log(_response)

    _authInfo = _response

    return this._FBUserProfile();

  }).then((success) => {
    this.TEST = "IM IN";
    let creds = (firebase.auth.FacebookAuthProvider as any).credential(_authInfo.authResponse.accessToken)
    let providerConfig = {
      provider: AuthProviders.Facebook,
      method: AuthMethods.OAuthToken,
      remember: 'default',
      scope: ['email'],
    };
    this.af.auth.login(creds, providerConfig)
      .then((success) => {
        console.log("Firebase success: " + JSON.stringify(success));
        this. Error += (JSON.stringify(success));
        this.UID =  success.auth.uid;
      })
      .catch((error) => {
        console.log("Firebase failure: " + JSON.stringify(error));
        this. Error += (JSON.stringify(error))
      });

  })
  .catch((_error) => { this. Error +=(_error)  }) //Error caught here.


}



 _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);
      });
  });
}

这些是我的导入。

import { Injectable } from '@angular/core';
import { AuthProviders, AngularFireAuth, FirebaseAuthState, AuthMethods, AngularFire } from 'angularfire2';
import { Platform } from 'ionic-angular';
import { Facebook } from 'ionic-native';

另外,请注意我在项目文件夹中运行了npm install firebase angularfire2 --save

【问题讨论】:

    标签: android firebase ionic2 firebase-authentication angularfire2


    【解决方案1】:

    你正在使用这个:

    firebase.auth.FacebookAuthProvider

    但是你没有导入 firebase,即使你导入了 angularfire,如果你像使用它一样使用它,你也需要 import firebase。

    所以尝试添加这个:

    import * as firebase from 'firebase';

    【讨论】:

      猜你喜欢
      • 2017-12-12
      • 2017-04-12
      • 2017-10-07
      • 2018-04-15
      • 2016-10-26
      • 2017-06-29
      • 2016-12-10
      • 2020-04-30
      • 2016-12-25
      相关资源
      最近更新 更多