I've been straggling for a while with this issue. I want to read users email once he is loged in using Facebook Login button. Here is my code
loginButton.setReadPermissions(Arrays.asList("email"));
loginButton.setSessionStatusCallback(new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state,
Exception exception) {
if (session.isOpened()) {
Log.i(TAG, "Access Token: " + session.getAccessToken());
Request.executeMeRequestAsync(session,
new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user,
Response response) {
if (user != null) {
Log.d(TAG,
""
+ user.asMap().get("email")
+ " is connected using facebook");
}
}
});
}
}
});
But I'm not even asked for email permission when approving the app. Thus I don't receive "email" in users JSON...
Any ideas?
Try this:
user.asMap().get("email");
What the code above should do is take the GraphUser
and turn it into a Java Collections Map
. Now, you call the get()
method on it with the "email"
parameter which will look through the Map for an email field and return one if present. Reference this link for more information on GraphObjects
. And this similar question for more information on how to get the user's email.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.