I'm using the following code to get email and name of the user from facebook
protected void onCreate(Bundle savedInstanceState) {
//Display page
setContentView(R.layout.activity_main);
AppEventsLogger.activateApp(MainActivity.this);
FBloginButton = (Button) findViewById(R.id.fb_login_button);
callbackManager = CallbackManager.Factory.create();
FBloginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Login the user through facebook when button is clicked
onFblogin();
}
});
}
private void onFblogin() {
callbackManager = CallbackManager.Factory.create();
// Set permissions
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email", "user_friends", "public_profile"));
//Try logging in the user
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
Log.i("LoginActivity", response.toString());
// Get facebook data from login
try {
email = object.getString("email");
} catch (JSONException e) {
e.printStackTrace();
}
try {
name = object.getString("name");
} catch (JSONException e) {
e.printStackTrace();
}
//new fbLogin().execute();
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "email, name");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
}
});
}
However, this only returns the name and not the email of the user. How can I get both?