我已经在这上面扯了好一阵子头发了。
我正在尝试使用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

最佳答案

您正在使用:
firebase.auth.FacebookAuthProvider
但是您没有导入firebase,即使您导入angularfire,如果您像使用一样使用它,也需要导入firebase。
因此,请尝试添加以下内容:
import * as firebase from 'firebase';

10-04 12:16
查看更多