Twitter Log In Button Greyed Out

3.2k Views Asked by At

I'm trying to implement logging in with twitter in my app. I just came across news that states that Fabric was sold to Google. I am not using Fabric in my application. Instead I am using the twitter core sdk com.twitter.sdk.android:twitter-core:3.1.1 . I try to initialise Twitter but the login button is still greyed out with this code:

TwitterConfig config = new TwitterConfig.Builder(this)
                .logger(new DefaultLogger(Log.DEBUG))
                .twitterAuthConfig(new TwitterAuthConfig(getString(R.string.twitter_key), getString(R.string.twitter_secret)))
                .debug(true)
                .build();
        Twitter.initialize(config);


I see the following error output in my logcat
E/Twitter: Must initialize Twitter before using getInstance()

How can I go about this error?

1

There are 1 best solutions below

3
Manny265 On BEST ANSWER

To solve the problem, I took my Twitter.initialize(TwitterConfig) statement before Android's setContentView() method and problem solved:

Sample Code

 TwitterConfig config = new TwitterConfig.Builder(this)
            .logger(new DefaultLogger(Log.DEBUG))
            .twitterAuthConfig(new TwitterAuthConfig(getString(R.string.twitter_key), getString(R.string.twitter_secret)))
            .debug(true)
            .build();
    Twitter.initialize(config);
    setContentView(R.layout.activity_login);
    mLoginButton = (TwitterLoginButton) findViewById(R.id.login_twitter);
    mLoginButton.setCallback(new Callback<TwitterSession>() {}