I was give the permission to get the email from facebook account. Eventhough i couldn't get it. it always an empty string. here is my code. please help me.
i'm adding the code i use. it is copied from stackoverflow.
fbLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LoginManager.getInstance().logInWithReadPermissions(LoginActivity.this, Arrays.asList("public_profile","email","basic_info"));
}
});
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest.newMeRequest(
loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject user, GraphResponse response) {
if (response.getError() != null) {
// handle error
} else {
socialData = new ArrayList<NameValuePair>();
String email = user.optString("email");
String id = user.optString("id");
String name = user.optString("name");
socialData.add(new BasicNameValuePair("id",id));
socialData.add(new BasicNameValuePair("name",name));
socialData.add(new BasicNameValuePair("email",email));
Log.e("id",id);
Log.e("name",name);
Log.e("email",email);
Log.e("object",user.toString());
// send email and id to your web server
SocialLogin socialLogin = new SocialLogin();
socialLogin.execute("app/social-login");
}
}
}).executeAsync();
}
@Override
public void onCancel() {
Toast.makeText(LoginActivity.this, "Login Cancel", Toast.LENGTH_LONG).show();
}
@Override
public void onError(FacebookException exception) {
Toast.makeText(LoginActivity.this, exception.getMessage(), Toast.LENGTH_LONG).show();
}
});
'
and here is my output
E/id﹕ 1046433868724117
E/name﹕ Jafer Poovan P
E/email﹕ '