Member 12185198 Ответов: 2

Как получить email id от facebook пользователя в android


Как получить email id от facebook пользователя в android

Richard MacCutchan

Спросите у facebook.

2 Ответов

Рейтинг:
2

ridoy

Попробуйте этот код:

facebookLoginBtn.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
    @Override
    public void onSuccess(LoginResult loginResult) {
        GraphRequest.newMeRequest(
            loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(JSONObject me, GraphResponse response) {
                    if (response.getError() != null) {
                        // handle error
                    } else {
                        // get email and id of the user
                        String email = me.optString("email");
                        String id = me.optString("id");
                        }
                }
            }).executeAsync();
    }

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

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


Рейтинг:
0

Member 13195403

Facebooklogin.setReadPermissions("email");
Facebooklogin.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 me, GraphResponse response) {

                                if (response.getError() != null) {
                                    // handle error
                                } else {
                                    
                                    String user_lastname = me.optString("last_name");
                                    String user_firstname = me.optString("first_name");
                                    String user_email =response.getJSONObject().optString("email");

                                    lastname.setText(user_lastname);
                                    name.setText(user_firstname);
                                    email.setText(user_email);

                                }
                            }
                        });

                Bundle parameters = new Bundle();
                parameters.putString("fields", "last_name,first_name,email");
                request.setParameters(parameters);
                request.executeAsync();
            }

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

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