Get list of tweets in custom timeline using Fabric Android
I am using the following code:
UserTimeline userTimeline = new UserTimeline.Builder().screenName("ZainAlabdin878").build();
final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter(MainActivity.this, userTimeline);
System.out.println(adapter.getCount()+"");
I get output 0 even though I have tweets.
Am I doing something wrong? I'm trying to get a list of tweets from a specific user. I am using android studio and plugin.
* my goal is not to display a list, but rather to get a list
many thanks.
source to share
final TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
Fabric.with(context, new Twitter(authConfig), new TweetUi());
TwitterCore.getInstance().logInGuest(new Callback<AppSession>() {
@Override
public void success(Result<AppSession> result) {
AppSession session = result.data;
TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient(session);
twitterApiClient.getStatusesService().userTimeline(tweetId, screenName, tweetCount, null, null, false, false, false, true, new Callback<List<Tweet>>() {
@Override
public void success(Result<List<Tweet>> listResult) {
for (Tweet tweet : listResult.data) {
// here you will get list
}
}
@Override
public void failure(TwitterException e) {
e.printStackTrace();
}
});
}
@Override
public void failure(TwitterException e) {
Log.e(TAG, "Load Tweet failure", e);
}
});
source to share
Here's the code you need to get the objects Tweet
:
ArrayList<Tweet> tweets = new ArrayList<>();
TwitterCore.getInstance().getApiClient(session).getStatusesService()
.userTimeline(null,
"screenname",
10 //the number of tweets we want to fetch,
null,
null,
null,
null,
null,
null,
new Callback<List<Tweet>>() {
@Override
public void success(Result<List<Tweet>> result) {
for (Tweet t : result.data) {
tweets.add(t);
android.util.Log.d("twittercommunity", "tweet is " + t.text);
}
}
@Override
public void failure(TwitterException exception) {
android.util.Log.d("twittercommunity", "exception " + exception);
}
});
You will need to run this on a new thread (not on the UI thread)
EDIT
* Technically, you don't need to run this on a new thread because it is asynchronous (someone please correct me here if I'm wrong). I know that other Twitter API calls are asynchronous, so I assume that is too, although I cannot find where the actual call is happening in the Fabric source. *
Here's a complete list of options for userTimeline () from the Fabric SDK
void userTimeline(@Query("user_id") Long var1, @Query("screen_name") String var2, @Query("count") Integer var3, @Query("since_id") Long var4, @Query("max_id") Long var5, @Query("trim_user") Boolean var6, @Query("exclude_replies") Boolean var7, @Query("contributor_details") Boolean var8, @Query("include_rts") Boolean var9, Callback<List<Tweet>> var10);
source to share