Search code examples
javaandroidtwitterandroid-studiotwitter-fabric

show timeline of twitter using fabric : Must Initialize Fabric before using singleton()


I want to display timeline using a particular screenName i am getting this error:-

Must Initialize Fabric before using singleton()

By the way ,I am suppose to use automatic guest authentication. Here is my Java code:-

import android.app.ListActivity;
import android.os.Bundle;

import com.twitter.sdk.android.tweetui.TweetTimelineListAdapter;
import com.twitter.sdk.android.tweetui.UserTimeline;

public class TimelineActivity extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.timeline);

        final UserTimeline userTimeline = new UserTimeline.Builder()
                .screenName("fabric")
                .build(); //HERE I AM GETTING THIS ERROR
        final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter(this, userTimeline);
        setListAdapter(adapter);
    }
}

Solution

  • I got it solved by myself. Just add below two lines . Do n't forget to edit and paste your Consumer Key (API Key) & Consumer Secret (API Secret).

    TwitterAuthConfig authConfig =  new TwitterAuthConfig("add your Consumer Key (API Key) ", "Consumer Secret (API Secret)");
    Fabric.with(this, new TwitterCore(authConfig), new TweetUi());
    

    before

    final UserTimeline userTimeline = new UserTimeline.Builder().screenName("fabric").build()