我已经把头发拉了一段时间了。
我正在尝试将Facebook Auth用于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
但是您不是在导入火池,即使您导入了Angularfire,如果您使用的是使用它,则需要导入燃料。
所以尝试添加以下内容:
import * as firebase from 'firebase';