how to get email id from facebook sdk in android applications?

I integrated Facebook login in my android application. I want to get email id of login user. How will I get it?

private void loginToFacebook() {
    Session.openActiveSession(this, true, new Session.StatusCallback() {

        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if (session.isOpened()) {
                Log.i(TAG, "Access Token" + session.getAccessToken());
                Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        if (user != null) {
                            try {

                                 userID =user.getId();
                                 provider="facebook";
                                 userName=user.getUsername();
                                 firstName=user.getFirstName();
                                 lastName=user.getLastName();
                                 Log.d("****User****", "details:" + user);
                                 }catch(Exception e){

Here is my code. i use Request.GraphUserCallback() method but there is no response of email from this method.

  • TextureView vs. GLSurfaceView or How to use GLSurfaceView with EGL14
  • Difference between SparseArray Vs ArrayList?
  • SyncAdapter: Account created, requestSync OK, but setSyncAutomatically not Working
  • ORM performance: is greenDAO faster than ORMLite?
  • Android - ActionBar SearchView suggestions with a simple String array
  • Reliable way of detecting whether an Android app is running in 'BlueStacks'
  • Related posts:

    How to show the copyright symbol in a Android dialog?
    AdMob can't display ads because of configChanges
    When should I get Width View in Fragment
    Android Custom font Spannable Typeface Span
    http connection timeout issues
    Adding a fragment to a dialog
  • Human body part detection in Android
  • Purpose of Service Intent-Filter inside Manifest.xml
  • Genymotion Error: “Unable to load VirtualBox Engine” on Yosemite. VirtualBox installed
  • Can you have two AsyncTasks in one Activity?
  • Get SSID when WIFI is connected
  • How do I prevent ListView footer from becoming selected?
  • 3 Solutions collect form web for “how to get email id from facebook sdk in android applications?”

    Before calling Session.openActiveSession do this to get permissions add this:

    List<String> permissions = new ArrayList<String>();
    permissions.add("email");
    

    The last parameter in Session.openActiveSession() should be permissions.
    Now you can access user.getProperty("email").toString().

    EDIT:

    This is the way I am doing facebook authorization:

    List<String> permissions = new ArrayList<String>();
    permissions.add("email");
    
    loginProgress.setVisibility(View.VISIBLE);
    
    //start Facebook session
    openActiveSession(this, true, new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if (session.isOpened()) {
                //make request to the /me API
                Log.e("sessionopened", "true");
                Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        if (user != null) {
                            String firstName = user.getFirstName();
                            String lastName = user.getLastName();
                            String id = user.getId();
                            String email = user.getProperty("email").toString();
    
                            Log.e("facebookid", id);
                            Log.e("firstName", firstName);
                            Log.e("lastName", lastName);
                            Log.e("email", email);
                        }
                    }
                });
             }
         }
     }, permissions);
    

    Add this method to your activity:

    private static Session openActiveSession(Activity activity, boolean allowLoginUI, Session.StatusCallback callback, List<String> permissions) {
        Session.OpenRequest openRequest = new Session.OpenRequest(activity).setPermissions(permissions).setCallback(callback);
        Session session = new Session.Builder(activity).build();
        if (SessionState.CREATED_TOKEN_LOADED.equals(session.getState()) || allowLoginUI) {
            Session.setActiveSession(session);
            session.openForRead(openRequest);
            return session;
        }
        return null;
    }
    

    Following the suggestion of Egor N, I change my old code

    Session.openActiveSession(this, true, statusCallback);
    

    whith this new one:

    List<String> permissions = new ArrayList<String>();
    permissions.add("email");
    Session.openActiveSession(this, true, permissions, statusCallback);
    

    Now FB ask the user about the permission of email and I can read it in the response.

    Try this article. Hope your issues will be solved Click Here

    Btw, You need to use user.asMap().get("email").toString()); for receving the User Email ID.
    Also, you need to assign that into some of label like lblEmail.setText where lblEmail is a Textview.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.