I am logging in with facebook with cordova-plugin-facebook4, I implemented it as it appears on the main page https://ionicframework.com/docs/native/facebook/ . It only gives me the facebook id, I would like to bring the email and the name.
i did it this way
config.xml
<plugin name="cordova-plugin-facebook4" spec="^1.9.1">
<variable name="APP_ID" value="APP_id" />
<variable name="APP_NAME" value="miproyecto" />
</plugin>
app.module.ts
import { Pages } from '../pages/pages';
import { Facebook } from '@ionic-native/facebook';
@NgModule({
declarations: [
pages
.....
],
imports: [
IonicModule.forRoot(MyApp,config, ['ngAnimate'])
],
bootstrap: [IonicApp],
entryComponents: [
......
],
providers: [
Notifying,
{provide: ErrorHandler, useClass: IonicErrorHandler},
....
Facebook
]
})
export class AppModule {}
login.ts
import { Facebook, FacebookLoginResponse } from '@ionic-native/facebook';
export class Login {
constructor(
private fb: Facebook
) {}
loginFace(ev?: Event){
this.fb.login(['public_profile', 'user_friends', 'email'])
.then((res: FacebookLoginResponse) => {
console.log('Logged into Facebook!', res)
let idFacebook = res.authResponse.userID;
this.fb.api(res.authResponse.userID+"/?fields=id,email,first_name,last_name", [])
.then(re => console.log(res))
.catch(e => console.log(e));
})
.catch(e => {
console.log('Error logging into Facebook', e)
});
}
}
console
where does it say
Replace it with
You are seeing the result of the first request.
I understand from the facebook api that when you get a login it will only return an access key and that with it you get an authorization json for the fields you require, that is if your app previously requested those fields in the login request to facebook and the request is to http://graph.facebook.com/ {userId}?fields=id,email,name&access_token={access-token}