2016-09-06 3 views
-3

これは私が自分のアプリケーションを実行すると、Twitterのボタンをクリックすることができないと動作していない表示されます。AndroidのTwitterのログインボタン[firebase払い]エラー:Twitterのに:(シングルトンを使用する前に、ファブリックを初期化する必要があります)

img

これは、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); 
     } 
    }); 

私は方法OnCreateにこのコードを配置:

TwitterAuthConfig authConfig = new TwitterAuthConfig(
       getString(R.string.twitter_consumer_key), 
       getString(R.string.twitter_consumer_secret)); 
     Fabric.with(this, new Twitter(authConfig)); 
私はこのようなOnActivityResultに設定

:その後、私はこのようなエラーが出る

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

アリ::これは私がonClickさえずりボタンで呼び出す方法twitterSessionためのコードである

mLoginButton.onActivityResult(requestCode, resultCode, data); 

E/Twitter: Must Initialize Fabric before using singleton() 

答えて

0

Application.javaonCreate()、このコードを追加します。

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イベントで

+0

は助け@Cristikいただきありがとうございます。私はこのコードを試してみますが、 "Twitter:シングルトン()を使用する前にファブリックを初期化する必要があります"のようなエラーです。多分誰でも私を助けることができる –

0

、前ではなく、以下のコードの後setContentView機能を置く:

TwitterAuthConfig authConfig = new TwitterAuthConfig(
      getString(R.string.twitter_consumer_key), 
      getString(R.string.twitter_consumer_secret)); 
Fabric.with(this, new Twitter(authConfig)); 
関連する問題