Collect User Data Facebook SDK

1

I have the following code to log in to 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 the callBack is returned, through the user ID I try to get information such as name, email and the photo using 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 it returns is name , id and gender :

  

I / FACEBOOK: {"id": "0000000000", "name": "Thiago   Domacoski "," gender ":" male "}

How do I get the user's email?

    
asked by anonymous 04.01.2017 / 17:24

1 answer

1

I think you need to put email here:

login_button.setReadPermissions("public_profile");

So:

login_button.setReadPermissions("public_profile", "email);

It is also good to check on the facebook site, if the email permission is released (it should be automatic but better see).

    
05.01.2017 / 17:34