Cannot set callback when loading custom timeline using Fabric Twitter Kit in Android app

I use Fabric Twitter Kit to upload custom graphs. However, I cannot get callbacks to work properly. I follow the official examples, but still my success and failure methods are not called.

Here is my complete code:

 public class TwitterFragment extends ListFragment { final Callback<Tweet> callback = new Callback<Tweet>() { @Override public void success(Result<Tweet> result) { setListShown(true); Toast.makeText(getActivity(), "NotFail", Toast.LENGTH_LONG).show(); } @Override public void failure(TwitterException e) { Toast.makeText(getActivity(), "Fail", Toast.LENGTH_LONG).show(); } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); startWork(); } public void startWork() { final UserTimeline userTimeline = new UserTimeline.Builder().screenName(Config.TWITTER_ACCOUNT).build(); final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(getActivity()) .setOnActionCallback(callback).setTimeline(userTimeline).setViewStyle(R.style.tw__TweetDarkStyle).build(); setListAdapter(adapter); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.twitter_layout, container, false); } } 

Any ideas how to make everything work?

+4
source share
2 answers

Ended up figuring this out.

Callback type must be `TimelineResult. Your code should look like this:

 final Callback<TimelineResult<Tweet>> callback = new Callback<TimelineResult<Tweet>>() { @Override public void success(Result<TimelineResult<Tweet>> result) { Log.d("TAG", "success"); progressDialog.dismiss(); } @Override public void failure(TwitterException e) { Log.d("TAG", "Failure"); progressDialog.dismiss(); Toast.makeText(getActivity(), "Error", Toast.LENGTH_LONG).show(); } }; adapter = new TweetTimelineListAdapter.Builder(getActivity()).setTimeline(userTimeline).build(); userTimeline.next(null, callback); 
+1
source

You just need to call

 //for the first time userTimeline.next(null, callback); 

after that you can provide the last tweet Id as the first argument to get the tweets after the last tweet id.

You do not upload any tweets, that’s it.

Hope this helps.

0
source

All Articles