Reputation: 16777
I'm using the following code to get user's email:
AccessToken accessToken = AccessToken.getCurrentAccessToken();
GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
// Obtaining
}
}).executeAsync();
The following is checked via debugger:
Profile has email — I'm authenticating via email.
I'm using Facebook SDK 4.5
EDIT: Request via direct HTTP graph api call returns email. But Android SDK does not.
How to fix it?
Upvotes: 2
Views: 257
Reputation: 442
Try this out, you need to send "email" as part of parameters for GraphRequest
.
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email");
request.setParameters(parameters);
request.executeAsync();
Upvotes: 2
Reputation: 147
Maybe we facing same problem, try this :
Bundle params=new Bundle();
params.putString("fields","id,name,email,verified"); //must specify the "fields" param, otherwise FB always return id and name only.
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me",
params,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
//do something...
}
}
).executeAsync();
Upvotes: 0
Reputation: 632
I think the user can specify no email permissions when he/she signs in via facebook. So even if you expect it, you might not get the email address.
Upvotes: 1