1
I have the following code to log into Facebook:
final FacebookCallback facebookCallback = new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Toast.makeText(getApplicationContext(), "Complete!!!", Toast.LENGTH_SHORT).show();
executeGraphRequest(loginResult.getAccessToken().getUserId());
}
@Override
public void onCancel() {
Toast.makeText(getApplicationContext(), "Facebook Cancel!", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException error) {
Toast.makeText(getApplicationContext(), "Facebook error: "+error.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}
};
login_button = LoginButton.class.cast(findViewById(R.id.login_button));
login_button.setReadPermissions("public_profile");
login_button.registerCallback(callbackManager, facebookCallback);
When callback is returned, through the user ID I try to get the information such as name, email and photo using the GraphRequest
:
private void executeGraphRequest(final String userId){
GraphRequest request =new GraphRequest(AccessToken.getCurrentAccessToken(), userId, null, HttpMethod.GET, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
Log.i("FACEBOOK", response.getJSONObject().toString());
Log.i("FACEBOOK", Profile.getCurrentProfile().toString());
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id, name, email, gender, birthday");
request.setParameters(parameters);
request.executeAsync();
}
But the only information he returns is the name
, id
and gender
:
I/FACEBOOK: {"id":"0000000000","name":"Thiago Domacoski","gender":"Le"}
How do I get the user’s email?
So, Facebook only releases the email if the user confirmed the same!
– Thiago Luiz Domacoski