Twitter Fabric Login for Android

Jacob Collins picture Jacob Collins · Oct 29, 2014 · Viewed 19k times · Source

I'm attempting to use the new Fabric API that Twitter is offering to let users login to my app. I've followed the tutorial exactly (at least I think I have, maybe I've made some mistakes) here after setting up my project with all of the necessary steps; now when I hit the login button and authenticate the button gives back a successful response but when I go to get the Twitter Session after that I get an exception that looks like

Caused by: java.lang.IllegalStateException: Must start Twitter Kit with Fabric.with() first    

(again, I followed the tutorial to a T up to this point, but if you can think of anything then I'd be willing to try it)

Answer

Cipriani picture Cipriani · Oct 29, 2014

The Fabric SDK separates functionality into modules called Kits. You must indicate which kits you wish to use via Fabric.with(). This is typically done by extending Android’s Application class.

package com.example.app;
import android.app.Application;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        TwitterAuthConfig authConfig = 
                   new TwitterAuthConfig("consumerKey",
                                         "consumerSecret");

        Fabric.with(this, new Twitter(authConfig));

        // Example: multiple kits
        // Fabric.with(this, new Twitter(authConfig),
        //                  new Crashlytics());
    }
}

More info: https://dev.twitter.com/twitter-kit/android/integrate

See the canonical sample app at: https://github.com/twitterdev/cannonball-android