callbacks not getting invoked in android facebook SDK

I am using facebook integration in my app for login.I have used facebook SDK 4.2.Everything is working fine.After pressing login button facebook login is prompted and followed by permission page.But as soon as i give permission no callback is invoked in code even though permission are provided as i can check in my facebook account.Below is the code for callback

public void onActivityCreated(@Nullable Bundle savedInstanceState) {

    super.onActivityCreated(savedInstanceState);
    loginButton = (LoginButton) getView().findViewById(R.id.connectWithFbButton);
    loginButton.setCompoundDrawablePadding(50);
    List<String> permissionNeeds = Arrays.asList("user_photos", "email", "user_birthday", "public_profile");
    loginButton.setReadPermissions(permissionNeeds);
    loginButton.setFragment(this);

    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            System.out.println("onSuccess");
            Log.v("LoginActivity", "onSuccess");

            AccessToken token = loginResult.getAccessToken();

            GraphRequest request = GraphRequest.newMeRequest
                    (loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject object, GraphResponse response) {
                            // Application code
                            //  Log.v("LoginActivity", response.toString());
                            System.out.println("Check: " + response.toString());
                            try {
                                String id = object.getString("id");
                                String name = object.getString("name");
                                String email = object.getString("email");
                                String gender = object.getString("gender");
                                String birthday = object.getString("birthday");


                                Toast.makeText(getActivity(), "Logged In", Toast.LENGTH_SHORT);
                                System.out.println(id + ", " + name + ", " + email + ", " + gender + ", " + birthday);
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }
                    });
            Bundle parameters = new Bundle();
            parameters.putString("fields", "id,name,email,gender, birthday");
            request.setParameters(parameters);
            request.executeAsync();
        }

        @Override
        public void onCancel() {
            System.out.println("onCancel");
        }

        @Override
        public void onError(FacebookException exception) {
            System.out.println("onError");

        }
    });

}`

Also i have overriden the onActivityResult();

public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}

Please suggest any solutions?


Source: facebook

Leave a Reply