artem
artem

Reputation: 16777

Facebook Android SDK — no 'email' in meRequest

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

Answers (3)

shreks7
shreks7

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

Taiwanese
Taiwanese

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

inder_gt
inder_gt

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

Related Questions