但是,当使用电容器将其导出为android项目时,它将调用手机浏览器以激活登录过程。它会关闭进程,但永远不会返回到应用程序。
我无法找出解决方案,帮助会非常有帮助。代码如下所示。
export class GsinginComponent implements OnInit {
private clientId:string = 'xxx.apps.googleusercontent.com';
private scope = [
'profile',
'email',
'https://www.googleapis.com/auth/plus.me',
'https://www.googleapis.com/auth/contacts.readonly',
'https://www.googleapis.com/auth/admin.directory.user.readonly'
].join(' ');
public auth2: any;
public async googleInit() {
let that = this;
gapi.load('auth2', function () {
that.auth2 = gapi.auth2.init({
client_id: 'xxx.apps.googleusercontent.com',
cookiepolicy: 'single_host_origin',
scope: that.scope
});
that.attachSignin(that.element.nativeElement.firstChild);
});
}
public attachSignin(element) {
let that = this;
this.auth2.attachClickHandler(element, {},
function (googleUser) {
console.log(gapi.auth2.getAuthInstance());
let profile = googleUser.getBasicProfile();
var id_token = googleUser.getAuthResponse().id_token;
console.log('Token || ' + id_token);
console.log('ID: ' + profile.getId());
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail());
//YOUR CODE HERE
// localStorage.setItem('token', id_token )
that._auth.registerGoogleUser(id_token, profile.getName(), profile.getEmail());
//that.router.navigateByUrl('inicio');
//that.router.navigate(['inicio']);
that.navCtrl.navigateRoot('/inicio');
}, function (error) {
console.log(JSON.stringify(error, undefined, 2));
});
}
constructor(private element: ElementRef, private router: Router, private _auth : AuthService, private navCtrl: NavController) {
console.log('ElementRef: ', this.element);
}
ngOnInit() {
this.googleInit();
}
}
我使用Ionic创建了一个Google登录应用,当它作为网络应用运行时,它可以完美运行。但是,使用电容器将其导出为android项目时,它会调用手机浏览器...