I am using Fabric Twitter Kit for loading user timelines. However, I am not able to make callbacks work properly. I follow the official examples, but still my success
and failure
methods are not called.
Here is my full 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?
Ended up figuring it out.
The Callback
's type needs to 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);
You just have to call
//for the first time
userTimeline.next(null, callback);
after that you can provide last tweet Id as first argument to get tweets after the last tweet id.
You are not loading any tweets, that's all.
I hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.