import { Facebook } from '@ionic-native/facebook/ngx';
async loginWithFacebook() {
console.log('www');
const loading = await this.loadingController.create({
content: 'Please wait...'
});
await loading.present();
// let permissions = new Array<string>();
//the permissions your facebook app needs from the user
let permissions = ['public_profile', 'user_friends', 'email'];
this.fb.login(permissions)
.then((response ) => {
console.log('qqq');
let userId = response.authResponse.userID;
//Getting name and gender properties
this.fb.api("/me?fields=name,email", permissions)
.then(user => {
user.picture = "https://graph.facebook.com/" + userId + "/picture?type=large";
//let patient = user;
//now we have the users info, let's save it in the storage
this.restProvider.faceBookLogin(user.email)
.subscribe(res => {
//return from reset api after check patient
let patient = res.data;
this.storage.set('token',
patient.token)
//after successfully save token save patient data
.then(() => {
this.storage.set('patient_info',
{
photo: user.photo,
code: patient.code,
name: user.name,
email: user.email,
facebook: true
})
}).catch(error => console.error('Error storing item', error));
this.navCtrl.setRoot('TabsPage');
loading.dismiss();
}, err => {
loading.dismiss();
console.log(err);
});
})
}, error => {
console.log(error);
loading.dismiss();
});
/*this.pressedButton = "facebookPressed";
this.loginEmitter.emit(this.pressedButton);*/
}