Facebook登录方法Onload

时间:2018-02-09 10:12:56

标签: java android facebook login

我只有一个问题。可以在facebook登录api上制作一个onLoad方法吗?

这是我的代码:

loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            LoginButton loginButton = (LoginButton) findViewById(R.id.facebook_login_button);
            loginButton.setVisibility(View.INVISIBLE);
            handleFacebookAccessToken(loginResult.getAccessToken());
        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException error) {
            Toast.makeText(LoginActivity.this, "Login Failed.", Toast.LENGTH_LONG).show();
        }

    });

1 个答案:

答案 0 :(得分:1)

是的,有可能。

CallbackManager callbackManager = CallbackManager.Factory.create();

LoginButton loginButton =(LoginButton)findViewById(R.id.facebook_login_button); loginButton.registerCallback(mCallbackManager,新的F​​acebookCallback(){

    @Override
    public void onSuccess(LoginResult loginResult) {

        loginButton.setVisibility(View.INVISIBLE);
        handleFacebookAccessToken(loginResult.getAccessToken());
    }

    @Override
    public void onCancel() {

    }

    @Override
    public void onError(FacebookException error) {
        Toast.makeText(LoginActivity.this, "Login Failed.", Toast.LENGTH_LONG).show();
    }

});

并使用此

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