How to get Facebook user data post login

Hello

i am able to login to Facebook. I am not sure on what i need to do to be able to get the user email, picture, name, city etc

i am logging into facebook like this

this.fb.login(['public_profile', 'user_friends', 'email'])
      .then((res: FacebookLoginResponse) => {
...
      })
      .catch(e => {
   ...
   });

can you please help me find how to get this data?

What is this? We have no idea what library you are using.

Hi Sujan

this.fb is from the Facebook class under @ionic-native/facebook

Then you have successfully logged in and in res or via this.fb.getAccessToken() you have the access_token to make a request to the Facebook API. You can probably directly use this.fb.api() from https://ionicframework.com/docs/native/facebook/#api for this - you only have to find the correct endpoint.

userData: any;

constructor(private facebook: Facebook) { }

loginWithFB() {
this.facebook.login([‘email’, ‘public_profile’]).then((response: FacebookLoginResponse) => {
this.facebook.api(‘me?fields=id,name,email,first_name,picture.width(720).height(720).as(picture_large)’, []).then(profile => {
this.userData = {email: profile[‘email’], first_name: profile[‘first_name’], picture: profile[‘picture_large’][‘data’][‘url’], username: profile[‘name’] }
});
});
}

and in html
<button ion-button full (click)=“loginWithFB()”>Login!

<ion-card *ngIf=“userData”>
{{ userData.username }}
<img [src]=“userData.picture” />

Email: {{ userData.email }}


First Name: {{ userData.first_name }}


Is Logged: {{ isLogged() }}



try this:

to complete the GOOD answer of @nezir you can add “last_name” in “id,name,email,first_name,picture.width(720).height(720).as(picture_large)” and like that you could get the first and the last without effort !