@feliperiverot wrote:
I developed an app with Ionic 4. I added a facebook login. Testing the add I saw that the facebook login fails in devices with android 9, with this message:“Login Error: There is an error in logging you into this application. Please try again later”.
But the login works well with device with android 5,6 and 7.
This is my ionic specifications:
And I build the app with android sdk 8:
This is my code:
import { Component } from '@angular/core'; import { FormGroup, FormBuilder, Validators } from "@angular/forms"; import { Router } from '@angular/router'; import { NativeStorage } from '@ionic-native/native-storage/ngx'; import { Facebook, FacebookLoginResponse } from '@ionic-native/facebook/ngx'; import { GooglePlus } from '@ionic-native/google-plus/ngx'; @Component({ selector: 'app-home', templateUrl: 'home.page.html', styleUrls: ['home.page.scss'], }) export class HomePage { ionicForm: FormGroup= this.formBuilder.group({ email: ['', [Validators.required, Validators.pattern('[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}] keyuser: ['', [Validators.required, Validators.minLength(6), Validators.pattern('^(?=.*[0-9])(?=.*[a-z])([a-z0-9_-]+)
isSubmitted = false; emailvalue:any; passclave:any; emailusuario = ""; isLoggedIn = false; users = { id: '', name: '', email: '', picture: { data: { url: '' } } };
constructor( public formBuilder: FormBuilder, private router: Router, private nativeStorage: NativeStorage,private fb: Facebook, private googlePlus:GooglePlus ) {
this.nativeStorage.getItem(‘email’)
.then(
data => this.emailusuario=data,
error => console.error(error)
);fb.getLoginStatus()
.then(res => {
console.log(res.status);
if (res.status === ‘connect’) {
this.isLoggedIn = true;
this.router.navigateByUrl("/tutorial");
} else {
this.isLoggedIn = false;
}
})
.catch(e => console.log(e));}
get errorControl() {
return this.ionicForm.controls;
}register() {
if(this.isSubmitted){ this.isSubmitted=false; } this.isSubmitted = true;
if (!this.ionicForm.valid) {
console.log(‘Please provide all the required values!’)
return false;
} else {
console.log(this.ionicForm.value)
var a =this.ionicForm.value;this.nativeStorage.getItem('email')
.then(
data => this.emailvalue=data,
error => console.error(error)
);this.nativeStorage.getItem(‘keyuser’)
.then(
data => this.passclave=data,
error => console.error(error)
);if( a.email.trim() == this.emailvalue && a.keyuser.trim() == this.passclave ){ this.router.navigateByUrl("/tutorial"); }
}
}fbLogin() {
this.fb.login([‘public_profile’, ‘user_friends’, ‘email’])
.then(res => {
if (res.status === ‘connected’) {
this.isLoggedIn = true;
this.getUserDetail(res.authResponse.userID);
this.router.navigateByUrl("/tutorial");
} else {
this.isLoggedIn = false;
}
})
.catch(e => console.log(‘Error logging into Facebook’, e));
}getUserDetail(userid: any) {
this.fb.api(’/’ + userid + ‘/?fields=id,email,name,picture’, [‘public_profile’])
.then(res => {
console.log(res);
this.users = res;
})
.catch(e => {
console.log(e);
});
}logout() {
this.fb.logout()
.then( res => this.isLoggedIn = false)
.catch(e => console.log(‘Error logout from Facebook’, e));
}async doGoogleLogin(){
this.googlePlus.login({ 'scopes': '', // optional, space-separated list of scopes, If not included or empty, defaults to `profile` and `email`. 'webClientId': '1021194051942-l3a9pra25mto4dd6lpjaos9p7i3t9dj1.apps.googleusercontent.com', // optional clientId of your Web application from Credentials settings of your project - On Android, this MUST be included to get an idToken. On iOS, it is not required. 'offline': true // Optional, but requires the webClientId - if set to true the plugin will also return a serverAuthCode, which can be used to grant offline access to a non-Google server }) .then(user =>{ this.nativeStorage.setItem('google_user', { name: user.displayName, email: user.email, picture: user.imageUrl }) .then(() =>{ this.router.navigateByUrl("/tutorial"); }, error =>{ this.router.navigateByUrl("/tutorial"); }) }, err =>{ this.router.navigateByUrl("/tutorial"); });
}
doGoogleLogout(){
this.googlePlus.logout()
.then(res =>{
//user logged out so we will remove him from the NativeStorage
this.nativeStorage.remove(‘google_user’);
this.router.navigateByUrl("/home");
}, err =>{
console.log(err);
})
}}
0 I developed and app with Ionic 4. I added a facebook login. Testing the add I saw that the facebook login fails in devices with android 9, with this message:"Login Error: There is an error in logging you into this application. Please try again later". enter image description here But the login works well with device with android 5,6 and 7. This is my ionic specifications: enter image description here And I build the app with android sdk 8: enter image description here This is my code: import { Component } from '@angular/core'; import { FormGroup, FormBuilder, Validators } from "@angular/forms"; import { Router } from '@angular/router'; import { NativeStorage } from '@ionic-native/native-storage/ngx'; import { Facebook, FacebookLoginResponse } from '@ionic-native/facebook/ngx'; import { GooglePlus } from '@ionic-native/google-plus/ngx'; @Component({ selector: 'app-home', templateUrl: 'home.page.html', styleUrls: ['home.page.scss'], }) export class HomePage { ionicForm: FormGroup= this.formBuilder.group({ email: ['', [Validators.required, Validators.pattern('[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,3}$')]], keyuser: ['', [Validators.required, Validators.minLength(6), Validators.pattern('^(?=.*[0-9])(?=.*[a-z])([a-z0-9_-]+)$')]] }); isSubmitted = false; emailvalue:any; passclave:any; emailusuario = ""; isLoggedIn = false; users = { id: '', name: '', email: '', picture: { data: { url: '' } } }; constructor( public formBuilder: FormBuilder, private router: Router, private nativeStorage: NativeStorage,private fb: Facebook, private googlePlus:GooglePlus ) { this.nativeStorage.getItem('email') .then( data => this.emailusuario=data, error => console.error(error) ); fb.getLoginStatus() .then(res => { console.log(res.status); if (res.status === 'connect') { this.isLoggedIn = true; this.router.navigateByUrl("/tutorial"); } else { this.isLoggedIn = false; } }) .catch(e => console.log(e)); } get errorControl() { return this.ionicForm.controls; } register() { if(this.isSubmitted){ this.isSubmitted=false; } this.isSubmitted = true; if (!this.ionicForm.valid) { console.log('Please provide all the required values!') return false; } else { console.log(this.ionicForm.value) var a =this.ionicForm.value; this.nativeStorage.getItem('email') .then( data => this.emailvalue=data, error => console.error(error) ); this.nativeStorage.getItem('keyuser') .then( data => this.passclave=data, error => console.error(error) ); if( a.email.trim() == this.emailvalue && a.keyuser.trim() == this.passclave ){ this.router.navigateByUrl("/tutorial"); } } } fbLogin() { this.fb.login(['public_profile', 'user_friends', 'email']) .then(res => { if (res.status === 'connected') { this.isLoggedIn = true; this.getUserDetail(res.authResponse.userID); this.router.navigateByUrl("/tutorial"); } else { this.isLoggedIn = false; } }) .catch(e => console.log('Error logging into Facebook', e)); } getUserDetail(userid: any) { this.fb.api('/' + userid + '/?fields=id,email,name,picture', ['public_profile']) .then(res => { console.log(res); this.users = res; }) .catch(e => { console.log(e); }); } logout() { this.fb.logout() .then( res => this.isLoggedIn = false) .catch(e => console.log('Error logout from Facebook', e)); } async doGoogleLogin(){ this.googlePlus.login({ 'scopes': '', // optional, space-separated list of scopes, If not included or empty, defaults to `profile` and `email`. 'webClientId': '1021194051942-l3a9pra25mto4dd6lpjaos9p7i3t9dj1.apps.googleusercontent.com', // optional clientId of your Web application from Credentials settings of your project - On Android, this MUST be included to get an idToken. On iOS, it is not required. 'offline': true // Optional, but requires the webClientId - if set to true the plugin will also return a serverAuthCode, which can be used to grant offline access to a non-Google server }) .then(user =>{ this.nativeStorage.setItem('google_user', { name: user.displayName, email: user.email, picture: user.imageUrl }) .then(() =>{ this.router.navigateByUrl("/tutorial"); }, error =>{ this.router.navigateByUrl("/tutorial"); }) }, err =>{ this.router.navigateByUrl("/tutorial"); }); } doGoogleLogout(){ this.googlePlus.logout() .then(res =>{ //user logged out so we will remove him from the NativeStorage this.nativeStorage.remove('google_user'); this.router.navigateByUrl("/home"); }, err =>{ console.log(err); }) } } Can be fix in some way?
Posts: 1
Participants: 1