Bug in SearchTweetsRecursively?

Jul 8, 2014 at 2:19 AM

It seems there is a bug in:
        while (result.Count < tweetSearchParameters.MaximumNumberOfResults)
            if (currentResult.IsEmpty())
                // If Twitter does not any result left, stop the search

            var oldestTweetId = _tweetHelper.GetOldestTweetId(currentResult);
            searchParameter.MaxId = oldestTweetId;
            searchParameter.MaximumNumberOfResults = Math.Min(tweetSearchParameters.MaximumNumberOfResults - result.Count, 100);
            query = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
            currentResult = GetTweetDTOsFromSearch(query);
I believe it needs to be:
            searchParameter.MaxId = oldestTweetId - 1;
The reason being that the documentation https://dev.twitter.com/docs/api/1.1/get/search/tweets says:

max_id: Returns results with an ID less than (that is, older than) or equal to the specified ID.

That means that it'll repeat the max_id.

Particularly bad is when i search for a term that's rare (e.g. #kasper) => it returns only 40 results or so. Then it loops until exhausting the search quota (as the "if" statement never gets triggered => it'll always return the last 1 result)...

Jul 9, 2014 at 4:53 PM
The same bug seems to be in the other method where MaxId is used... Replacing it with oldestTweetId - 1 works correctly. Am I mistaken?
Jul 9, 2014 at 7:28 PM
It seems that you are totally right. It is therefore a bug.

I logged the bug here.