Quantcast
Channel: Tweetinvi a friendly Twitter C# library
Viewing all articles
Browse latest Browse all 4126

Created Unassigned: SearchTweetsRecursively breaks prematurely [2138]

$
0
0
Hello!

Let me first congratulate you on a fantastic job. The framework has some brilliant uses.

I noticed that when searching for tweets greater than the max (>100), there are varied results. I will see no where near my input amount, despite it being well under the rate limit (i've tried 200 - 10,000) and the number of results seem to be different each time.

I stepped through the code and think I have found the issue. There is an if statement in the below method which breaks once the returned result is less than the count parameter you supplied. Now I can see the reason for this - presumably if the count is less, then the rate limit has been hit! But, I have found this is not always the case. Sometimes the Twitter API can be a little intermittent and return 99 results instead of my 100 max, in which case the method breaks and there are still plenty of tweets which could be returned!

In fact, if you comment out that code altogether, I was seeing 10,000 results returned instead of the 1000 max previously.

The code potentiallly needs to be altered so that the method breaks only if the rate limit has actually been hit. Simply commenting out is not enough because an exception is thrown when trying to parse an empty HTTP result set.

Many thanks,
keep up the great work,

James.

private IEnumerable<ITweetDTO> SearchTweetsRecursively(ITweetSearchParameters tweetSearchParameters)
{
var searchParameter = CloneTweetSearchParameters(tweetSearchParameters);
searchParameter.MaximumNumberOfResults = Math.Min(searchParameter.MaximumNumberOfResults, 100);

string httpQuery = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
var currentResult = GetTweetDTOsFromSearch(httpQuery);
List<ITweetDTO> result = currentResult;

while (result.Count < tweetSearchParameters.MaximumNumberOfResults)
{
var oldestTweetId = GetOldestTweetId(currentResult);
searchParameter.MaxId = oldestTweetId;
searchParameter.MaximumNumberOfResults = Math.Min(tweetSearchParameters.MaximumNumberOfResults - result.Count, 100);
httpQuery = _searchQueryGenerator.GetSearchTweetsQuery(searchParameter);
currentResult = GetTweetDTOsFromSearch(httpQuery);
result.AddRange(currentResult);

if (currentResult.Count < searchParameter.MaximumNumberOfResults)
{
// There is no other result
break;
}
}

return result;
}

Viewing all articles
Browse latest Browse all 4126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>