我想检索Facebook用户电子邮件,用户名和姓氏。我检索了姓名和姓氏。但我不知道如何检索电子邮件。
我有这段代码:
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();
}
}
};
如何检索用户邮件?我在Profile类中找不到getEmail的方法。我找到getName(),getFirstName()或getLastName()以获取名字和姓氏。
感谢。
我也有这段代码:
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();
}
运行之后,我看的是id和name,但没有电子邮件。怎么了?
答案 0 :(得分:0)
从registerCallback onSuccess
调用以下方法private void makeGraphRequest(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
Log.d("response: ", response + "");
try {
String id =object.getString("id").toString();
String email = object.getString("email").toString();
String name = object.getString("name").toString();
//String imageurl = "https://graph.facebook.com/" + id + "/picture?type=large";
//object.get("gender");
} catch (Exception e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender, birthday");
request.setParameters(parameters);
request.executeAsync();
}