just call this method will return user email id to you.
private void doSocialNetworkinWithFacebook()
{
// check for session
Session session=Session.getActiveSession();
if (session != null && session.isOpened())
{
// user is already login show
try
{
Session.OpenRequest request = new Session.OpenRequest(this);
request.setPermissions(Arrays.asList("email", "publish_actions"));
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
Request.executeMeRequestAsync(session, new Request.GraphUserCallback()
{
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response)
{
if (user != null)
{
Toast.makeText(activity, "Welcome "+user.getName(), Toast.LENGTH_SHORT).show();
// publishFeedDialog(session);
try
{
strFirstName = user.getFirstName().toString();
strLocation = user.getLocation().getProperty("name").toString();
strEmail = user.asMap().get("email").toString();
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
strEmail="";
}
runOnUiThread(new Runnable()
{
public void run()
{
setUserInfoFromFacebook(strFirstName, strLocation, strEmail);
}
});
}
}
});
}
else
{
// user is not log in
//show login screen
// start Facebook Login
try
{
Session.OpenRequest request = new Session.OpenRequest(this);
request.setPermissions(Arrays.asList("email", "publish_actions"));
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
Session.openActiveSession(activity, true, new Session.StatusCallback()
{
// callback when session changes state
@Override
public void call(final Session session, SessionState state, Exception exception)
{
//session.openForRead(new Session.OpenRequest(this).setPermissions(Arrays.asList("email")));
Log.d(TAG, "Session :"+session.toString());
Log.d(TAG, "Session is opened :"+session.isOpened());
if (session.isOpened())
{
// make request to the /me API
Request.executeMeRequestAsync(session, new Request.GraphUserCallback()
{
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response)
{
if (user != null)
{
Toast.makeText(activity, "Welcome "+user.getName(), Toast.LENGTH_SHORT).show();
// publishFeedDialog(session);
try
{
strFirstName = user.getFirstName().toString();
strLocation = user.getLocation().getProperty("name").toString();
strEmail = user.asMap().get("email").toString();
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
strEmail="";
}
runOnUiThread(new Runnable()
{
public void run()
{
setUserInfoFromFacebook(strFirstName, strLocation, strEmail);
}
});
}
}
});
}
else if(session.isClosed())
{
Toast.makeText(activity, "Unable to connect facebook, please try later..",Toast.LENGTH_SHORT).show();
}
}
});
}
}