skip to Main Content

I’m trying to get user_id, name & email from facebook via graph API. but its not sending me the email. I’m using a function like this:

void callGraphApi() {
        accessToken = AccessToken.getCurrentAccessToken();

        GraphRequest request = GraphRequest.newMeRequest(
                accessToken,
                new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(
                            JSONObject object,
                            GraphResponse response) {

                        tv_response.setText(response.toString());
                    }
                });
        Bundle parameters = new Bundle();
        parameters.putString("fields", "id,name,email");
        request.setParameters(parameters);
        request.executeAsync();
    }

I’m only getting a response like this:

{"id":"1480750682018443","name":"Ogwemuvwem Ossas","gender":"male"}, error: null}

Any solution??

2

Answers


  1. In your facebook developer dashboard Go to App review in There you can see your data request permission.

    enter image description here

    If email permission not listed there you have to add it by click start a submission button on the same page.

    enter image description here

    From facebook Docs:

    Note, even if you request the email permission it is not guaranteed
    you will get an email address. For example, if someone signed up for
    Facebook with a phone number instead of an email address, the email
    field may be empty.

    Login or Signup to reply.
  2. You can try this new api. You can pass permissions in ArrayList like this.

    loginButton.setReadPermissions(Arrays.asList("public_profile", "email"));
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            getUserDetails(loginResult);
        }
    
        @Override
        public void onCancel() {
            // App code
        }
    
        @Override
        public void onError(FacebookException exception) {
            // App code
        }
    });
    

    You can handle LoginResult like this.

      // Get Facebook login results
        protected void getUserDetails(LoginResult loginResult) {
            GraphRequest data_request = GraphRequest.newMeRequest(
                    loginResult.getAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject json_object, GraphResponse response) {
    
                            Log.i("onfbCompleted: ", json_object.toString());                    
    
                        }
    
                    });
            Bundle permission_param = new Bundle();
            permission_param.putString("fields", "id,name,email,picture.width(120).height(120)");
            data_request.setParameters(permission_param);
            data_request.executeAsync();
    
        }
    

    I Hope it’s help for you. 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search