登录后再次出现Facebook登录对话框

时间:2016-03-28 12:38:17

标签: android facebook-android-sdk

我根据他们的文档

实现了android登录

问题是,在用户输入其凭据(1个对话框)进行登录并确认应用程序权限(2对话框)之后,facebook连接只返回到(1对话框),再次请求凭据。为什么会这样?

在Facebook用户中,我可以在应用列表中看到该应用

这是我的代码:

CallbackManager callbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions("public_profile","user_friends");
    // Callback registration
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            // App code
            Log.i(Utils.TAG,"succesfull login to facebook");

            // App code
            GraphRequest request = GraphRequest.newMeRequest(
                    loginResult.getAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject object, GraphResponse response) {
                            Log.i("LoginActivity", response.toString());

                            try {
                            }catch (Exception e)
                            {   Log.i(Utils.TAG, e.getMessage());
                            }
                        }
                    });
        }

        @Override
        public void onCancel() {
            // App code
            Log.i(Utils.TAG,"onCancel login to facebook");
        }

        @Override
        public void onError(FacebookException exception) {
            // App code
            Log.i(Utils.TAG,"onError login to facebook");
            Log.i(Utils.TAG,exception.getMessage());
        }
    });



    loginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
    //        LoginManager.getInstance().logInWithReadPermissions((Activity)m_context, Arrays.asList("public_profile", "email", "user_birthday", "user_friends"));
            LoginManager.getInstance().logInWithReadPermissions((Activity)m_context, Arrays.asList("public_profile", "user_friends"));
        }
    });


}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.i(Utils.TAG,"onActivityResult called");
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);
}

我应该提一下,只有当我关闭对话框时才会在登录流程中调用回调

2 个答案:

答案 0 :(得分:2)

是的,这是因为您正在使用登录按钮和登录管理器。您只需从中选择一个..因为它们都具有相同的功能。我建议你从这里删除登录管理器代码。

 loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
        //        LoginManager.getInstance().logInWithReadPermissions((Activity)m_context, Arrays.asList("public_profile", "email", "user_birthday", "user_friends"));
                LoginManager.getInstance().logInWithReadPermissions((Activity)m_context, Arrays.asList("public_profile", "user_friends"));
            }
        });

oginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            // App code
            Log.i(Utils.TAG,"succesfull login to facebook");

            // App code
            GraphRequest request = GraphRequest.newMeRequest(
                    loginResult.getAccessToken(),
                    new GraphRequest.GraphJSONObjectCallback() {
                        @Override
                        public void onCompleted(JSONObject object, GraphResponse response) {
                            Log.i("LoginActivity", response.toString());

                            try {
                            }catch (Exception e)
                            {   Log.i(Utils.TAG, e.getMessage());
                            }
                        }
                    });
        }

        @Override
        public void onCancel() {
            // App code
            Log.i(Utils.TAG,"onCancel login to facebook");
        }

        @Override
        public void onError(FacebookException exception) {
            // App code
            Log.i(Utils.TAG,"onError login to facebook");
            Log.i(Utils.TAG,exception.getMessage());
        }
    });

答案 1 :(得分:0)

那是因为facebook登录api使用chrome浏览器。登录一次后,Chrome浏览器会保留该信息。如果您在Chrome浏览器中注销Facebook,则可能会出现“1对话框”。