
[英]unrecognized selector sent to instance - Ionic cordova Google-plus login
[英]Ionic's Google-Plus and Firebase-Authentication plugins not working when used together
Ionic(cordova)google-plus和firebase-authentication插件在一起使用时无法正常工作。
我正在尝试使用Ionic的google-plus和firebase-authentication插件来验证用户进入firebase。 google-plus插件正在独立工作,我正在获取idToken和accessToken。 当我添加firebase-authentication插件并运行构建时,没有任何反应。 没有谷歌加插件的响应,也没有错误。
以下是离子信息......
离子(离子CLI):4.1.0(/home/chandra/.npm-global/lib/node_modules/ionic)Ionic Framework:ionic-angular 3.9.5 @ ionic / app-scripts:3.2.2
cordova(Cordova CLI):9.0.0(cordova-lib@9.0.1)Cordova平台:android 7.1.1 Cordova插件:cordova-plugin-ionic-keyboard 2.1.3,cordova-plugin-ionic-webview 4.0.1, (和其他8个插件)
Android SDK工具:26.1.1 NodeJS:v8.10.0(/ usr / bin / node)npm:6.4.0操作系统:Linux 4.15
以下是单击“使用Google登录”按钮时调用的功能。
googlePlusLogin() {
console.log("Trying to do Gooogle sign-in ....");
this.gplus.login({ webClientId: "xxx.apps.googleusercontent.com" })
.then(res => {
console.log("Google response: ", res);
signinCallback(res);
})
.catch(err => console.error(err));
let me = this;
function signinCallback(authResult) {
let res = me.firebaseAuth.signInWithGoogle(
authResult.idToken,
authResult.accessToken
);
console.log("Firebase Auth Result: ", res);
}
}
我打算将google-plus插件提供的idToken和accessToken传递给firebase-authentication插件,以便firebase进行身份验证。
为什么要为Google Plus使用单独的插件(只是谷歌登录)? 我使用Firebase插件,Google身份验证只是由这段代码处理
import * as firebase from 'firebase';
...
googleLogin()
{
const provider = new firebase.auth.GoogleAuthProvider();
return this.afAuth.auth.signInWithPopup(provider).then((result) => {
var uid = result.user.uid
var name = result.user.displayName
var email = result.user.email
var photoURL = result.user.photoURL
this.linkUser(uid, email, name, photoURL)
})
}
我也在使用相同的东西,这对我有用:
async googleSignin(){
try{
const gpRes = await this.googlePlus.login({})
//webClientId is only required when we need the offline support, but for starting this is okay.
const credential = this.afAuth.auth.signInWithCredential(auth.GoogleAuthProvider.credential(null, gpRes.accessToken));
//Here also within Credential() first parameter is idToken and then accessToken, both are optional and I pass only the accessToken which is enough
//TODO: Get the signed in user data from credential.user and update UI or change the route
} catch (error){
//TODO: Handle error here
}
}
我希望这将有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.