无法通过Android中的Facebook应用登录

时间:2016-06-08 20:06:28

标签: android facebook facebook-graph-api facebook-authentication

我正在为我的Android应用创建一个Facebook登录方法。我正在使用我的自定义登录按钮。当没有安装Facebook应用程序时,这可以正常工作,我必须通过触摸登录按钮后出现的界面手动登录。我面临的问题是,安装Facebook应用程序时此方法无法正常工作。在这种情况下,当我触摸登录按钮时,它会启动带有标题“正在加载”的黑白圆形装载程序,并且装载程序将永远继续。没有登录。我该如何解决它?以下是实现的代码。

on onCreate方法

    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();
         }
    });

内部剩余方法

@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();
    }
};

1 个答案:

答案 0 :(得分:1)

这意味着您没有正确输入密钥哈希值。

请参阅此问题:Android facebook login not working with installed Facebook app