NativeScript / nativescript-facebook

NativeScript plugin, wrapper of native Facebook SDK for Android and iOS
Apache License 2.0
79 stars 50 forks source link

How to Get email address #115

Closed YoussefGheith closed 6 years ago

YoussefGheith commented 6 years ago

Is there any possible way to get the email address using this awesome plugin

The code i'm using to get the public profile is => http.getJSON(Config.FACEBOOK_GRAPH_API_URL + "/me?fields=first_name,last_name,picture,email&access_token=" + eventData.loginResponse.token).then((res) => { console.dir(res); the response object doesn't contain the email address only "public profile"

any suggestions ??

much appreciated ..

DimitarTodorov commented 6 years ago

Hi, @yonkoGH

Here is the Graph API User reference. There can be found information about the API. In your case the field that you need is the email. Here is an example how you can use it to observe the user's email:

http.getJSON(config.FACEBOOK_GRAPH_API_URL + "/" + this.userId + "?fields=email&access_token=" + this.accessToken).then((res) => {
  console.log("Email: " + res["email"])   
}, function (err){
  alert(err)
});

In the response of the request the field 'email' returns the desired value. Note that this field will not be returned if no valid email address is available.

Regards, NativeScript Team