I want to retrieve facebook user email, user name and last name. I retrieved name and last name. But I don't know how to retrieve email.
I have this code:
fbloginButton.registerCallback(callbackManager, new
FacebookCallback<LoginResult>()
{
@Override
public void onSuccess(LoginResult loginResult)
{
Intent intent = new
Intent(LoginTienda.this,Comprador_registrado.class);
startActivity(intent);
}
@Override
public void onCancel()
{
}
@Override
public void onError(FacebookException error)
{
String msgerror = error.getMessage();
Toast.makeText(LoginTienda.this, msgerror,
Toast.LENGTH_SHORT).show();
}
});
profileTracker = new ProfileTracker()
{
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile
currentProfile)
{
if(currentProfile == null)
{
Intent i = new
Intent(LoginTienda.this,MainActivity.class);
startActivity(i);
}
else
{
//get the username and last name
nombrefb = currentProfile.getFirstName();
apellidofb = currentProfile.getLastName();
Toast.makeText(getApplicationContext(),
apellidofb,Toast.LENGTH_LONG).show();
}
}
};
How can I retrieve the user mail? I can't find a method in Profile class as getEmail. I find getName(), getFirstName() or getLastName() in order to get the first name and the last name.
Thanks.
I also have this code:
public void onSuccess(LoginResult loginResult)
{
GraphRequest graphRequest = GraphRequest.newMeRequest(
loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback()
{
@Override
public void onCompleted(JSONObject object, GraphResponse response)
{
String rsp = response.toString();
Toast.makeText(getApplicationContext(),rsp,Toast.LENGTH_LONG).show();
try
{
correofb = object.getString("email").toString();
}
catch (JSONException e)
{
e.printStackTrace();
}
}
});
Bundle parametros = new Bundle();
parametros.putString("campos","email");
graphRequest.setParameters(parametros);
graphRequest.executeAsync();
}
And after running it what I watch is id and name but no email. What's wrong?