我已经为此烦恼了很长一段时间了。
我正在尝试对 Firebase 使用 Facebook 身份验证。我还在 app.module.ts 中初始化了我的应用程序 但是当我在 Android 设备上运行下面提到的代码时,我得到 p>
"RefrenceError: firebase is not defined"
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。
所以尝试添加这个:
从“firebase”导入*作为firebase;
关于android - IONIC 2 引用错误 : firebase is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42250279/