0

I am creating a Facebook login method for my Android app. I am using my custom login button. This works fine when Facebook app is not installed and I have to manually login through the interface that appears after touching login button. The problem I am facing is, this method does not work properly when Facebook app is installed. In this case, when I touch login button, it starts that black and white circular loader with caption "Loading" and that loader continues forever. No login takes place. How do I go about solving it? Following is the code implemented.

Inside onCreate method

    callbackManager=CallbackManager.Factory.create();
    loginButton= (LoginButton)findViewById(R.id.login_button);
    btnFBLogin= (TextView) findViewById(R.id.btnFBLogin);
    btnFBLogin.setSelected(true);
    btnFBLogin.startAnimation(animationButtonFadeIn);
    btnFBLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            progressDialog = new ProgressDialog(LoginActivity.this);
            progressDialog.setMessage("Loading...");
            progressDialog.show();
            loginButton.performClick();
            loginButton.setPressed(true);
            loginButton.invalidate();
            loginButton.registerCallback(callbackManager, mCallBack);
            loginButton.setPressed(false);
            loginButton.invalidate();
         }
    });

Inside Remaining Methods

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

private FacebookCallback<LoginResult> mCallBack = new FacebookCallback<LoginResult>() {
    @Override
    public void onSuccess(LoginResult loginResult) {
        progressDialog.dismiss();
        GraphRequest request = GraphRequest.newMeRequest(
                loginResult.getAccessToken(),
                new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(
                            JSONObject object,
                            GraphResponse response) {
                        try {
                            btnFBLogin.setVisibility(View.GONE);
                            user = new User();

                            facebook_id = object.getString("id").toString();
                            user.uniqueID = facebook_id;
                            full_name = object.getString("name").toString();
                            user.name = full_name;
                            try{
                                email = object.getString("email").toString();
                            }catch (Exception e){
                                email = "email_not_provided";
                            }finally {
                                user.email = email;
                            }
                            PrefUtils.setCurrentUser(user, LoginActivity.this);
                            userRecord(facebook_id, full_name, email, "fb", null);
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                });

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

    @Override
    public void onCancel() {
        progressDialog.dismiss();
    }

    @Override
    public void onError(FacebookException e) {
        progressDialog.dismiss();
    }
};
harshvardhan
  • 765
  • 13
  • 32

1 Answers1

1

That means you have not entered your key hash properly.

See this issue : Android facebook login not working with installed Facebook app

Community
  • 1
  • 1
Alexandre Martin
  • 1,472
  • 5
  • 14
  • 27
  • 1
    Thanks, it worked...! :) Actually i had entered the correct hashkey that I received from the singleton class in Android, but there was another key that was yet to be added to the facebook developers console. I got this key on the facebook login itself along with the error message, that I added to the console. – harshvardhan Jun 29 '16 at 07:28