Android twitter登录按钮[firebase auth]错误:twitter:在使用singleton()之前必须初始化结构

Android twitter登录按钮[firebase auth]错误:twitter:在使用singleton()之前必须初始化结构,android,firebase-authentication,twitter-fabric,Android,Firebase Authentication,Twitter Fabric,这在我运行应用程序时显示,twitter按钮无法单击且不起作用: 这是twitter登录按钮的代码: mLoginButton = (TwitterLoginButton) findViewById(R.id.button_twitter_login); mLoginButton.setCallback(new Callback<TwitterSession>() { @Override public void success(Result&

这在我运行应用程序时显示,twitter按钮无法单击且不起作用:

这是twitter登录按钮的代码:

mLoginButton = (TwitterLoginButton) findViewById(R.id.button_twitter_login);
    mLoginButton.setCallback(new Callback<TwitterSession>() {
        @Override
        public void success(Result<TwitterSession> result) {
            Log.d(TAG, "twitterLogin:success" + result);
            handleTwitterSession(result.data);
        }

        @Override
        public void failure(TwitterException exception) {
            Log.w(TAG, "twitterLogin:failure", exception);
            updateUI(null);
        }
    });
我设置了一个activityresult,如下所示:

mLoginButton.onActivityResult(requestCode, resultCode, data);
 E/Twitter: Must Initialize Fabric before using singleton()
这是我在
onClick
twitter按钮中调用的方法
twitterSession
的代码:

 private void handleTwitterSession(TwitterSession session) {
    Log.d(TAG, "handleTwitterSession:" + session);
    // [START_EXCLUDE silent]
    showProgressDialog();
    // [END_EXCLUDE]

    AuthCredential credential = TwitterAuthProvider.getCredential(
            session.getAuthToken().token,
            session.getAuthToken().secret);

    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());

                    // If sign in fails, display a message to the user. If sign in succeeds
                    // the auth state listener will be notified and logic to handle the
                    // signed in user can be handled in the listener.
                    if (!task.isSuccessful()) {
                        Log.w(TAG, "signInWithCredential", task.getException());
                        Toast.makeText(LoginActivity.this, "Authentication failed.",
                                Toast.LENGTH_SHORT).show();
                    }

                    // [START_EXCLUDE]
                    hideProgressDialog();
                    // [END_EXCLUDE]
                }
            });
}

Application.java
onCreate()
中,添加以下代码:

TwitterAuthConfig authConfig =  new TwitterAuthConfig(
                getString(R.string.twitter_consumer_key),
                getString(R.string.twitter_consumer_secret));

final Fabric fabric = new Fabric.Builder(this)
                .kits(new TwitterCore(authConfig))
                .logger(new DefaultLogger(Log.DEBUG))
                .debuggable(true)
                .build();

Fabric.with(fabric);

希望这有帮助。

在OnCreate中,将setContentView函数放在以下代码之后,而不是之前:

TwitterAuthConfig authConfig =  new TwitterAuthConfig(
            getString(R.string.twitter_consumer_key),
            getString(R.string.twitter_consumer_secret));
Fabric.with(this, new Twitter(authConfig));

谢谢你的帮助@Cristik。我尝试了这段代码,但仍然出现类似“Twitter:在使用singleton()之前必须初始化结构”的错误。也许有人能帮我
TwitterAuthConfig authConfig =  new TwitterAuthConfig(
            getString(R.string.twitter_consumer_key),
            getString(R.string.twitter_consumer_secret));
Fabric.with(this, new Twitter(authConfig));