facebook android getEmail
<p>I am trying to get the user's email who has logged in with facebook.</p>

<p>This is my code <code>String userId=(String) user.asMap().get("email");</code> it return null, How can i fix it?</p>

<p>i read that there is maybe a session permissions that i need to set? what is this permission? and where do i need to write this permission?</p>

<p>maybe its another problem?</p>

<pre><code>Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);

        Session session = Session.getActiveSession();
        if (session == null) {
            if (savedInstanceState != null) {
                session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
            }
            if (session == null) {
                session = new Session(this);
            }
            Session.setActiveSession(session);
            if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
                session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
            }
        }

        updateView();

   //    End of OnCreate Method&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;
    }

    @Override
    public void onStart() {
        super.onStart();
        Session.getActiveSession().addCallback(statusCallback);
    }

    @Override
    public void onStop() {
        super.onStop();
        Session.getActiveSession().removeCallback(statusCallback);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        Session session = Session.getActiveSession();
        Session.saveSession(session, outState);
    }

    private void updateView() {
        Session session = Session.getActiveSession();
        session.openForRead(new Session.OpenRequest(this).setPermissions(Arrays.asList("email")));

        if (session.isOpened()) {
            //button logout string
            buttonLoginLogout.setOnClickListener(new OnClickListener() {
                public void onClick(View view) { onClickLogout(); }
            });
        } else {
            //button log in string
            buttonLoginLogout.setOnClickListener(new OnClickListener() {
                public void onClick(View view) { onClickLogin(); }
            });
        }
    }

    private void onClickLogin() {
        Session session = Session.getActiveSession();
        if (!session.isOpened() &amp;&amp; !session.isClosed()) {
            session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
        } else {
            Session.openActiveSession(this, true, statusCallback);
        }
    }

    private void onClickLogout() {
        Session session = Session.getActiveSession();
        if (!session.isClosed()) {
            session.closeAndClearTokenInformation();
        }
    }

    private class SessionStatusCallback implements Session.StatusCallback {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if( session.isOpened() ){
                Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        Intent i = new Intent(getApplicationContext(), ProfileActivity.class);
                        String userId=(String) user.asMap().get("email");
                        i.putExtra("epuzzle",userId  );
                        startActivity(i);
                    }
                });
            }
            updateView();
        }


    }
</code></pre>

<p>and this is my manifest file:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.sale"
    android:versionCode="1"
    android:versionName="1.0" &gt;

    &lt;uses-feature
        android:glEsVersion="0x00020000"
        android:required="true"/&gt;

    &lt;uses-sdk
        android:minSdkVersion="11"
        android:targetSdkVersion="10" /&gt;
    &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
    &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
    &lt;uses-permission android:name="android.permission.CAMERA"/&gt;
    &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/&gt;
    &lt;!-- The following two permissions are not required to use
     Google Maps Android API v2, but are recommended. --&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;
    &lt;permission
        android:name="com.example.sale.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/&gt;
        &lt;uses-permission android:name="com.example.sale.permission.MAPS_RECEIVE"/&gt;



    &lt;application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" &gt;



        &lt;activity
            android:name="com.example.sale.MainActivity"
            android:label="@string/app_name" &gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;

                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;


              &lt;/activity&gt;

         &lt;!--  Entry for RegisterActivity.class --&gt;
        &lt;activity android:name=".RegisterActivity"
                  android:label="Register New Account"&gt;&lt;/activity&gt;
        &lt;meta-data android:value="@string/app_id" android:name="com.facebook.sdk.ApplicationId"/&gt;
        &lt;activity android:label="@string/app_name" android:name="com.facebook.LoginActivity"&gt;&lt;/activity&gt;
        &lt;activity android:name=".ProfileActivity" android:label="Profile page"&gt;&lt;/activity&gt;

        &lt;meta-data
              android:name="com.google.android.maps.v2.API_KEY"
              android:value="AIzaSyDTVRXMTmfe3jZyAlt-87kRgqM8y4TzIto"/&gt;

    &lt;/application&gt;

&lt;/manifest&gt;
</code></pre>
