Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google plus login in ionic returns error 10

I am using google plus login in ionic application. Login functionality is properly working 4.2, 4.3 android devices. But it returns error:10 in 5+ android versions. For this i am using this plugin 'cordova-plugin-googleplus'. I installed it by Cordova CLI and npm

Here is my code.

     window.plugins.googleplus.login(
        {},
        function (user_data) {
          alert(JSON.stringify(user_data));   
        },
        function (msg) {
          alert(msg);
        }
    );

I didn't get any working solutions from my search. Please help me to solve this issue.

Thanks in advance.

like image 473
Madhu Avatar asked Nov 05 '16 06:11

Madhu


2 Answers

After so much troubleshooting, i found the proper solution

Three possibilities are there

1) May be you use the android client id during the install the plugin - in this case you should only use the webclient id even though you build for android - Screenshot attached

2) You should only use DEBUG SHA1 key during build of the debug apk and use PROD SHA1 key during production release apk.

  • You can also add both DEBUG and PROD SHA1 key in firebase console. Please find attached screenshot for more info.

Screenshot1

Debug SHA1 Command : keytool -exportcert -keystore ~/.android/debug.keystore -list -v - Make sure ~/.android/debug.keystore is default keystore provide by android SDK, no need to change. password : android

Release SHA1 Command : keytool -exportcert -keystore ~/your-path/playstore-release-sample.keystore -list -v - where ~/your-path/playstore-release-sample.keystore is your keystore which you are using during generate the signed APK

3) You should on pass the webclientID during the google log api not and android client id.

enter image description here

Webclient ID only - Find in attached screenshot
 **'webClientId': '900429691586-.............apps.googleusercontent.com',**

async login() {
    let params;
    if (this.platform.is('android')) {
      params = {
        'webClientId': '900429691586-.............apps.googleusercontent.com',
        'offline': true
      }
    }
    else {
      params = {}
    }
    this.googlePlus.login(params)
      .then((response) => {
        const { idToken, accessToken } = response
        this.onLoginSuccess(idToken, accessToken);
      }).catch((error) => {
        console.log(error)
        this.globalService.showSimpleAlertMessage('Getting Error :' + JSON.stringify(error), "OK")
      });   }   onLoginSuccess(accessToken, accessSecret) {
    const credential = accessSecret ? firebase.auth.GoogleAuthProvider
      .credential(accessToken, accessSecret) : firebase.auth.GoogleAuthProvider
        .credential(accessToken);
    this.firebaseAuth.auth.signInWithCredential(credential)
      .then((response) => {
        this.storage.set("firebaseSuccessResponse", response)
        this.router.navigate(["/home"]);
        this.globalService.hideLoading();
      })   }   onLoginError(err) {
    console.log(err);   }

Hope this step resolve your problem permanently

like image 146
Yogesh Kumar Avatar answered Oct 16 '22 05:10

Yogesh Kumar


Give all credits to ERROR:10 , what am i missing ??

I spent a couple of hours searching this issue for my ionic 3 application. The mistake I was made is I was using Client ID for Android.

The ionic app should use Client ID for Web!

like image 5
Haifeng Zhang Avatar answered Oct 16 '22 07:10

Haifeng Zhang