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.
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?
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="?????"
There seems to have been some more recent development. You might wish to try installing the newer fork from GitHub . 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:
GooglePlus.prototype.login = function (options, successCallback, errorCallback)
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);
});
}
}
I folow this tutorial, but it is for ionic v1
so my problem is call it in ionic 2.
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
Someone has the solution?
I used the Cordova Plugin instead of Ionic Native. It is working just fine.
Done.
1 - Add the plugin
2 - Do some stuff for google dev oAuth
(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);
}
);
1 Like
Thanks, that worked for me!
1 Like
@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);
}
);
}
}
Dahpu
October 24, 2016, 8:12am
13
@trangtraan_rose Where you using ‘ionic serve’? I just had the same issue, but the last comment on this issue helped me. Building and testing the app on my android phone works!
It’s woking fine for me !
I have created a credentials on Google dev console
but I have this error :
any idea ?
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
Anujp
December 3, 2016, 9:15am
16
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
It’s wok fine on ios but not with andorid.
Error 12501
For google authentication in Ionic 2 app for android just follow this… it works…!
1 Like