在 android 中集成 Facebook SDK 并检索用户的电子邮件

Integrate Facebook SDK in android and retrieve user's email

我想检索登录用户的电子邮件。这是我绑定的,但没有检索电子邮件。我只能检索 id, first name, last name 但不能检索 email

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.v("LoginActivity", response.toString());

                            // Application code
                            try {
                                String userEmail = object.getString("email");
                                String userId = object.getString("id");
                                emailEditText.setText(userEmail);
                                new SignupTask(SignupActivity.this, userId, userEmail).execute();

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }
                    });

            Bundle parameters = new Bundle();
            parameters.putString("fields", "id, first_name, last_name, email"); // Parámetros que pedimos a facebook
            request.setParameters(parameters);
            request.executeAsync();
        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException e) {

        }
    });

    LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "email", "user_friends"));

我错过了什么....

CallbackManager callbackManager ;

//in OnCreate  initialize it
callbackManager = CallbackManager.Factory.create();


//after that overide onActivityResult
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

callbackManager.onActivityResult(requestCode, resultCode, data);
        }
ohk..try this code its working for me...    

LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
        loginButton.setBackgroundResource(R.drawable.fb);
        loginButton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
        loginButton.setReadPermissions(Collections.singletonList("public_profile, email, user_birthday, user_friends"));

        callbackManager = CallbackManager.Factory.create();
        if (netWorkStatus) {
            LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {
                    // App code
                    //Store Facebook data to webservice .
                    GraphRequest request = GraphRequest.newMeRequest(
                            loginResult.getAccessToken(),
                            new GraphRequest.GraphJSONObjectCallback() {
                                @Override
                                public void onCompleted(JSONObject object, GraphResponse response) {
                                    // Application code
                                    try {
                                        // String picture = object.getString("picture");
                                        //JSONObject jobj = new JSONObject(picture);
                                        //JSONObject dataObj = jobj.getJSONObject("data");

                                        name = object.getString("name");
                                        userEmail = object.getString("email");
                                        //String url = dataObj.getString("url").replace("\", "");

                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }

                                }
                            });

                    Bundle parameters = new Bundle();
                    parameters.putString("fields", "id,name,email,gender,birthday,picture");
                    request.setParameters(parameters);
                    request.executeAsync();

                }

                @Override
                public void onCancel() {
                    // App code

                }

                @Override
                public void onError(FacebookException exception) {
                    // App code

                }

            });
        }