Reputation: 1417
I am having trouble getting email from Facebook in my app. I have googled a lot and came across many answers but nothing is working in my case. I followed the same method described here, but the value returning is null. Below given is my code. And also I have added User & Friend permissions as email in the facebook app. It would be of great help if someone could point out the mistake I might be doing.
private void makeMeRequest(final Session session) {
Request request = Request.newMeRequest(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
if (session == Session.getActiveSession()) {
if (user != null) {
profilePictureView.setProfileId(user.getId());
facebook_id = String.valueOf(user.getId());
fullName.setText(user.getName());
if (user.asMap().get("email") != null)
email.setText(user.asMap().get("email")
.toString());
}
}
if (response.getError() != null) {
}
}
});
Bundle params = request.getParameters();
params.putString("fields", "email,name");
request.setParameters(params);
request.executeAsync();
}
Upvotes: 1
Views: 617
Reputation: 623
Depending on your needs this might be suitable.
I'm using https://github.com/sromku/android-simple-facebook instead of the bloated Facebook SDK. And with that it's pretty easy to get e-mail.
mSimpleFacebook.getProfile(new OnProfileRequestAdapter()
{
@Override
public void onComplete(Profile profile)
{
String id = profile.getId();
String firstName = profile.getFirstName();
String birthday = profile.getBirthday();
String email = profile.getEmail();
String bio = profile.getBio();
// ... and many more properties of profile ...
}
});
Upvotes: 1
Reputation: 4683
The request looks OK. The reason for null
value of email property is usually lack of email
permission.
You wrote:
And also I have added User & Friend permissions as email in the facebook app
What do you mean by facebook app? You need to ask for permissions in your app.
Take a look at this solution. I think it can help you: https://stackoverflow.com/a/18147719/334522
Upvotes: 1