Reputation: 1050
I am getting a null pointer exception while getting an email address from Facebook API on Android 3.0.
The code generating the exception is below:
LoginButton authButton;
authButton = (LoginButton) findViewById(R.id.authButton);
// set permission list, Don't forget to add email
authButton.setReadPermissions(Arrays.asList("basic_info", "email"));
authButton.setSessionStatusCallback(new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
showToast("Inside Call");
if (session.isOpened()) {
showToast("Inside Session");
System.out.println("facebook Access Token"
+ session.getAccessToken());
fbToken = session.getAccessToken();
Request.executeMeRequestAsync(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user,
Response response) {
if (user != null) {
String email = user.asMap().get("email").toString();
}
}
});
}
}
});
The code was working previously - I might have made a mistake while integrating code.
Upvotes: 1
Views: 1240
Reputation: 1897
You can get the user email from the GraphUser Object by using the property.
user.getProperty("email").toString()
It works for me.Hoping it will also work for you.
Upvotes: 2