# How to add an ionic 2 google login

**URL:** <https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114>\
**Category:** ionic-v3\
**Created:** [May 3, 2016, 9:55pm UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114 "2016-05-03T21:55:14Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![eeggersd](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/eeggersd/32/100253_2.png) [@eeggersd](https://forum.ionicframework.com/u/eeggersd)\
**Post date:** [May 3, 2016, 9:55pm UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/1 "2016-05-03T21:55:14Z")

</div>

Hi, i am trying to connect my app with Google, but the button don’t work

i added the cordova-plugin-googleplus

cordova plugin add cordova-plugin-googleplus --variable REVERSED\_CLIENT\_ID="???"  
i think here is “com.ionicframework.gpxxxxxxx”

this is my code

import {Page} from ‘ionic-angular’;

@Page({  
templateUrl: ‘build/pages/home/home.html’  
})  
export class HomePage {  
constructor() {

}  
loginPlus(){  
alert(‘click working’);  
window.cordova.plugins.googleplus.login().then(  
(userData) =\> {  
alert(userData);  
var message = JSON.stringify(userData);  
alert(message);

```
	}, 
	(err) => {
		alert(err);
	});
}

```

}

and this is button

\<button success class=“button button-full” (click)=“loginPlus()”\>Login with Google

Please your help, thanks.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [May 3, 2016, 10:03pm UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/2 "2016-05-03T22:03:37Z")

</div>

There seem to be several versions of this plugin floating around. Can you provide at least a version number, and even better a link to the source code of the version you are using somewhere out there in GitHub?

---

<div class="post-metadata">

**Author:** ![eeggersd](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/eeggersd/32/100253_2.png) [@eeggersd](https://forum.ionicframework.com/u/eeggersd)\
**Post date:** [May 3, 2016, 10:59pm UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/3 "2016-05-03T22:59:52Z")

</div>

Hi,

id=“cordova-plugin-googleplus” version=“4.0.8”

i just add th pluggin with

`cordova plugin add cordova-plugin-googleplus --variable REVERSED_CLIENT_ID="?????"`

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [May 3, 2016, 11:11pm UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/4 "2016-05-03T23:11:46Z")

</div>

There seems to have been some more recent development. You might wish to try installing the newer fork [from GitHub](https://github.com/EddyVerbruggen/cordova-plugin-googleplus). In any event, what is really confusing me is your call to `login`. It seems to be expecting a `Promise` to be returned, but the call signature for that function looks to me to be expecting callbacks instead:

```auto
GooglePlus.prototype.login = function (options, successCallback, errorCallback)

```

---

<div class="post-metadata">

**Author:** ![eeggersd](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/eeggersd/32/100253_2.png) [@eeggersd](https://forum.ionicframework.com/u/eeggersd)\
**Post date:** [May 3, 2016, 11:51pm UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/5 "2016-05-03T23:51:09Z")

</div>

So, changing my question…

in my home.ts, how i must call the login method?

i want to create a function, and call this funcion in a button like this

`<button success class="button button-full" (click)="loginPlus()">Login with Google</button>`

* * *

```
import {Page} from 'ionic-angular';

@Page({
  templateUrl: 'build/pages/home/home.html'
})
export class HomePage {
  constructor() {

  }
  loginPlus(){
	????????????.then((userdata)=> {
		console.debug(userdata);
	},
	(err) => {
        console.debug(err);
        alert(err);
      });
  }
}
```

---

<div class="post-metadata">

**Author:** ![eeggersd](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/eeggersd/32/100253_2.png) [@eeggersd](https://forum.ionicframework.com/u/eeggersd)\
**Post date:** [May 4, 2016, 12:35am UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/6 "2016-05-04T00:35:48Z")

</div>

I folow this tutorial, but it is for ionic v1

> **[Add Google+ Login to your Ionic App | Tutorials | IonicThemes](https://ionicthemes.com/tutorials/about/google-plus-login-with-ionic-framework)**
>
> In this tutorial you will learn how to add Google+ Login to your Ionic App. This integration will allow your users to log in to your app with their Google+ account both on iOS and Android devices.

so my problem is call it in ionic 2.

---

<div class="post-metadata">

**Author:** ![panchoslimi](https://avatars.discourse-cdn.com/v4/letter/p/4da419/32.png) [@panchoslimi](https://forum.ionicframework.com/u/panchoslimi)\
**Post date:** [July 14, 2016, 7:52pm UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/7 "2016-07-14T19:52:31Z")

</div>

any suggestion about how to use google plus to login in ionic 2 ?

import {GooglePlus} from ‘ionic-native’;

GooglePlus.login().then((options) =\> {  
console.log(options);  
});

Error appear : zone.js:461 Unhandled Promise rejection: Object {} ; Zone: ; Task: null

---

<div class="post-metadata">

**Author:** ![Andrea-W](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/andrea-w/32/105938_2.png) [@Andrea-W](https://forum.ionicframework.com/u/Andrea-W)\
**Post date:** [July 27, 2016, 2:58pm UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/8 "2016-07-27T14:58:26Z")

</div>

Someone has the solution? 🙂

---

<div class="post-metadata">

**Author:** ![guilx15](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/guilx15/32/122636_2.png) [@guilx15](https://forum.ionicframework.com/u/guilx15)\
**Post date:** [July 28, 2016, 7:41pm UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/9 "2016-07-28T19:41:41Z")

</div>

I used the Cordova Plugin instead of Ionic Native. It is working just fine.

---

<div class="post-metadata">

**Author:** ![Andrea-W](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/andrea-w/32/105938_2.png) [@Andrea-W](https://forum.ionicframework.com/u/Andrea-W)\
**Post date:** [July 28, 2016, 8:27pm UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/10 "2016-07-28T20:27:05Z")

</div>

Done.  
1 - Add the plugin  
2 - Do some stuff for google dev oAuth

> ([GitHub - EddyVerbruggen/cordova-plugin-googleplus: ➕ Cordova plugin to login with Google Sign-In on iOS and Android](https://github.com/EddyVerbruggen/cordova-plugin-googleplus#3-google-api-setup)

3 - From .ts file, call the login function

```
window['plugins'].googleplus.login(
    {
      'scopes': '',
      'webClientId': '',
      'offline': false, 
    },
    function (obj) {
      alert(JSON.stringify(obj)); // do something useful instead of alerting
    },
    function (msg) {
      alert('error: ' + msg);
    }
);

```

---

<div class="post-metadata">

**Author:** ![GregoireDevauchelle](https://avatars.discourse-cdn.com/v4/letter/g/43a26b/32.png) [@GregoireDevauchelle](https://forum.ionicframework.com/u/GregoireDevauchelle)\
**Post date:** [September 26, 2016, 7:05pm UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/11 "2016-09-26T19:05:17Z")

</div>

Thanks, that worked for me!

---

<div class="post-metadata">

**Author:** ![trangtraan\_rose](https://avatars.discourse-cdn.com/v4/letter/t/5e9695/32.png) [@trangtraan\_rose](https://forum.ionicframework.com/u/trangtraan_rose)\
**Post date:** [October 7, 2016, 2:52am UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/12 "2016-10-07T02:52:21Z")

</div>

@Mocardini @GregoireDevauchelle I try but it got `Cannot read property 'googleplus' of undefined`  
about.ts  
import { Component } from ‘@angular/core’;

```
import { NavController } from 'ionic-angular';

@Component({
  selector: 'page-about',
  templateUrl: 'about.html'
})
export class AboutPage {

	
  constructor(public navCtrl: NavController) {

  }

  test() {
    window['plugins'].googleplus.login(
      {
        //'scopes': '',
        'webClientId': 'xxx.apps.googleusercontent.com',
        'offline': false, 
      },
      function (obj) {
        alert(JSON.stringify(obj)); // do something useful instead of alerting
      },
      function (msg) {
        alert('error: ' + msg);
      }
    );

  }

}
```

---

<div class="post-metadata">

**Author:** ![Dahpu](https://avatars.discourse-cdn.com/v4/letter/d/8e7dd6/32.png) [@Dahpu](https://forum.ionicframework.com/u/Dahpu)\
**Post date:** [October 24, 2016, 8:12am UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/13 "2016-10-24T08:12:35Z")

</div>

@trangtraan_rose Where you using ‘ionic serve’? I just had the same issue, but the last comment on [this issue](https://github.com/EddyVerbruggen/cordova-plugin-googleplus/issues/132) helped me. Building and testing the app on my android phone works!

---

<div class="post-metadata">

**Author:** ![ducmaxime](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ducmaxime/32/105019_2.png) [@ducmaxime](https://forum.ionicframework.com/u/ducmaxime)\
**Post date:** [November 25, 2016, 5:11pm UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/14 "2016-11-25T17:11:37Z")

</div>

It’s woking fine for me !

I have created a credentials on Google dev console

![image](https://global.discourse-cdn.com/ionicframework/original/3X/5/a/5a39bdef7e8c1105eb15178e5cd1f0f30de84829.png)

but I have this error :

 ![image](https://global.discourse-cdn.com/ionicframework/original/3X/2/5/2505efd3021adb62b2754f27e12f2e9f6790c5f8.png)

any idea ?

---

<div class="post-metadata">

**Author:** ![dayanajabif](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/dayanajabif/32/126298_2.png) [@dayanajabif](https://forum.ionicframework.com/u/dayanajabif)\
**Post date:** [November 30, 2016, 3:08pm UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/15 "2016-11-30T15:08:51Z")

</div>

I have built this step by step tutorial which explains **how to add Google Login to an Ionic 2 app.** I have also included the link to the github repo with the working example. Hope it helps: [https://ionicthemes.com/tutorials/about/ionic2-google-login](https://ionicthemes.com/tutorials/about/ionic2-google-login)

---

<div class="post-metadata">

**Author:** ![Anujp](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@Anujp](https://forum.ionicframework.com/u/Anujp)\
**Post date:** [December 3, 2016, 9:15am UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/16 "2016-12-03T09:15:44Z")

</div>

Hello,  
I hope you got success in the above issue, please help me out i have the same problem in the ios , in the android same thing works fine.

Thanks

---

<div class="post-metadata">

**Author:** ![ducmaxime](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ducmaxime/32/105019_2.png) [@ducmaxime](https://forum.ionicframework.com/u/ducmaxime)\
**Post date:** [December 8, 2016, 10:53am UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/17 "2016-12-08T10:53:56Z")

</div>

Its work, thx a lot ! 😉

---

<div class="post-metadata">

**Author:** ![ducmaxime](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ducmaxime/32/105019_2.png) [@ducmaxime](https://forum.ionicframework.com/u/ducmaxime)\
**Post date:** [December 8, 2016, 5:44pm UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/18 "2016-12-08T17:44:26Z")

</div>

It’s wok fine on ios but not with andorid.

Error 12501 ☹

---

<div class="post-metadata">

**Author:** ![dev\_reactore](https://avatars.discourse-cdn.com/v4/letter/d/49beb7/32.png) [@dev\_reactore](https://forum.ionicframework.com/u/dev_reactore)\
**Post date:** [December 12, 2016, 8:09am UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/19 "2016-12-12T08:09:58Z")

</div>

For google authentication in Ionic 2 app for android just follow this… it works…!👍

---

<div class="post-metadata">

**Author:** ![adansz](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@adansz](https://forum.ionicframework.com/u/adansz)\
**Post date:** [February 22, 2017, 8:36pm UTC](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114/20 "2017-02-22T20:36:22Z")

</div>

same, do you can fixed?

[Next page](https://forum.ionicframework.com/t/how-to-add-an-ionic-2-google-login/51114.md?page=2)
