I can not get the EMAIL from the Facebook API user

1

I can get all the other information, full name, birthday, gender but not the email.

My code:

    btn_fb_login.setOnClickListener(new View.OnClickListener() {

      @Override
          public void onClick(View view) {

          callbackManager = CallbackManager.Factory.create();
           LoginManager.getInstance().logInWithReadPermissions(activity,  
             Arrays.asList("public_profile", "email", "user_birthday"));

        LoginManager.getInstance().registerCallback(callbackManager,
                new FacebookCallback<LoginResult>() {
                    @Override
                    public void onSuccess(final LoginResult loginResult) {

          final GraphRequest request = GraphRequest.newMeRequest(
                                loginResult.getAccessToken(),
                                new GraphRequest.GraphJSONObjectCallback() {
                                    @Override

         public void onCompleted(JSONObject object, GraphResponse response) {
                         try {
                           emailID = object.getString("email");
                         } catch (JSONException e) {
                              e.printStackTrace();
                         }

            try {                                                
                 Profile person = Profile.getCurrentProfile();                           
                 esFacebook = true;
                 finishActivity(object.getString("id") ,person.getName(), object.getString("gender"), person.getProfilePictureUri(240,240).toString());

                     } catch (JSONException e) {
                            e.printStackTrace();
                      }
                      }
                    });
                        Bundle parameters = new Bundle();
                        parameters.putString("fields", "id,name,email,gender,birthday");
                        request.setParameters(parameters);
                        request.executeAsync();
                        PedirDatosInicioSesionFacebook();

                    }
                    @Override
                    public void onCancel() {
                        Toast.makeText(getApplicationContext(), "Login Cancel", Toast.LENGTH_LONG).show();
                    }
                    @Override
                    public void onError(FacebookException exception) {
                        Toast.makeText(getApplicationContext(), exception.getMessage(), Toast.LENGTH_LONG).show();
                    }
                });
    }
});

}

    
asked by Nicolas Schmidt 20.08.2016 в 00:53
source

1 answer

2

Try adding the permissions to the login button and not the loginManager, here is the example of how it worked for me.

btnLogin = (LoginButton) findViewById(R.id.login_button);
    List<String> permissions = new ArrayList<>();
    permissions.add("public_profile");
    permissions.add("email");
    permissions.add("user_birthday");
    btnLogin.setReadPermissions(permissions);
    callbackManager = CallbackManager.Factory.create();
    
answered by 20.08.2016 в 01:27