How to get user email address using Parse Facebook for Android

I am trying to get the email address of a user from ParseFacebook for Android, but I get null when I try to get the email. here is my code

//on Login:

List<String> permissions = Arrays.asList("email","basic_info", "user_about_me", "user_location");
        ParseFacebookUtils.logIn(permissions,SignUpActivity. this, new LogInCallback() {
            @Override
            public void done(ParseUser user, ParseException err) {
                SignUpActivity.this.progressDialog.dismiss();
                if(err!=null)
                Log.w("parse exception",""+err.getMessage());
                if (user == null) {
                Log.e("FB","Uh oh. The user cancelled the Facebook login.");
                } else if (user.isNew()) {
                    Log.w("FB","User signed up and logged in through Facebook!");
                    //showUserDetailsActivity();
                    getProfileInfo();
                } else {
                    Log.w("FB","User logged in through Facebook!");
                //  showUserDetailsActivity();
                    getProfileInfo();
                }
            }

        });

inquiry:

Request request = Request.newMeRequest(ParseFacebookUtils.getSession(),new Request.GraphUserCallback() {
                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        if (user != null) {
                            JSONObject userProfile = new JSONObject();
                            try {
                                // Populate the JSON object
                                try {
                                    userProfile.put("facebookId", user.getId());
                                    userProfile.put("name", user.getName());
                                } catch (Exception e) {
                                    // TODO: handle exception
                                }
                                if (user.getProperty("email") != null) {
                                    userProfile.put("email",(String) user.getProperty("email"));
                                }
                                if (user.getLocation().getProperty("name") != null) {
                                    userProfile.put("location", (String) user.getLocation().getProperty("name"));
                                }
                                if (user.getProperty("gender") != null) {
                                    userProfile.put("gender",(String) user.getProperty("gender"));
                                }


                            } catch (JSONException e) {
                                Log.e("Facebook parsing data","Error parsing returned user data.");
                            }

                        } else if (response.getError() != null) {
                            if ((response.getError().getCategory() == FacebookRequestError.Category.AUTHENTICATION_RETRY) || (response.getError().getCategory() == FacebookRequestError.Category.AUTHENTICATION_REOPEN_SESSION)) {
                                Log.e("Facebook parsing data","The facebook session was invalidated.");
                                //onLogoutButtonClicked();
                            } else {
                                Log.e("Facebook parsing data","Some other error: "+ response.getError().getErrorMessage());
                            }
                        }
                    }
                });
        request.executeAsync();

I tried everything, but wherever I do, I get the email address :(

+4
source share
5 answers

After setting the permissions indicated above, you will get access to the email through: user.asMap (). get ("email"));

0
source

You should receive an email like this

String email = (String) response.getGraphObject().getProperty("email");
if(email!=null && !email.equals("")
//email variable should've email id.
0
source

.

ParseFacebookUtils.logIn(SignUpActivity.this, new LogInCallback() {
//you can add permissions on later screens.
}
0
source

Please add this query:

 Request request = Request.newMeRequest(ParseFacebookUtils.getSession(),new Request.GraphUserCallback() 

In login state, condition => user.isnew ()

else if (user.isNew()) {
                Log.w("FB","User signed up and logged in through Facebook!");
                //showUserDetailsActivity();
                getProfileInfo();
            }

write your block between this and you will also be able to receive new user information by e-mail.

This works great in iOS and will certainly help in android.

0
source

Before the line

request.executeAsync();

add these three lines.

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

You will now receive an email in your reply

0
source

Source: https://habr.com/ru/post/1533557/


All Articles