Twitter4j.getHomeTimeline method not retrieving the number of tweets as specified in the count consistently

android
twitter4j
java

#1

When i try to pull out twitter status using Twitter4j.getHomeTimeline(), the number of tweet received is not consistent, even though I am setting the count using paging.

For e.g. If NO_OF_TWEETS is 50, statuses.size() is not always 50

Any help would be appreciated.

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(consumerKey);
    builder.setOAuthConsumerSecret(consumerSecret);
    // Access Token
    String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, "");
    // Access Token Secret
    String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, "");

    AccessToken accessToken = new AccessToken(access_token, access_token_secret);
    Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);

    DbHelper dbHelper = new DbHelper(this);
    db = dbHelper.getWritableDatabase();

    ContentValues values = new ContentValues();
    ResponseList<Status> statuses = null;


    if(maxId != null) {

        Paging page1 = new Paging();
        page1.setCount(NO_OF_TWEETS);
        page1.setMaxId(maxId);
        statuses = twitter.getHomeTimeline(page1);

    }else{

        Paging page1 = new Paging();

        page1.setCount(NO_OF_TWEETS);
        page1.setSinceId(sinceId);
        statuses = twitter.getHomeTimeline(page1);
    }

/* below statement does not return 50 always, sometime 49, sometimes 46, even though there are more number of tweets */

    Log.d(TAG,"No. of new Statues : "+statuses.size());

#2

The documentation for GET statuses/home_timeline reads:

The value of count is best thought of as a limit to the number of tweets
to return because suspended or deleted content is removed after the
count has been applied.


#3

Thanks for your reply. Do you know how to check for deleted and suspended tweets?


#4

I am creating a little twitter app in which I am loading the tweets in a listview and adding “load more items” textview after the list of tweets if there are more tweets available.

Issue is that how can I find out if there are more tweets available as twitter4j.getHometimeline() is sometimes retrieving the less number of tweets than specified in the COUNT even if there a more tweets available. I want to display “load more items” text view only when more tweets are available.


#5

(moving this to the REST API category since it is not related to Fabric / Twitter Kit)