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

New Post: How to get long followers list

$
0
0
As promised, please find an improved version of the code:
// Retrieve all the follower ids the RateLimit tokens authorize in one goprivate IEnumerable<IIdsCursorQueryResultDTO> GetFollowerIds(string username, long cursor, outlong nextCursor)
{
    var query = string.Format("https://api.twitter.com/1.1/followers/ids.json?screen_name={0}", username);

    // Ensure that we can get some information
    RateLimit.AwaitForQueryRateLimit(query);
    var results = TwitterAccessor.ExecuteCursorGETCursorQueryResult<IIdsCursorQueryResultDTO>(query, cursor : cursor).ToArray();

    if (!results.Any())
    {
        // Something went wrong. The RateLimits operation tokens got used before we performed our query
        RateLimit.ClearRateLimitCache();
        RateLimit.AwaitForQueryRateLimit(query);
        results = TwitterAccessor.ExecuteCursorGETCursorQueryResult<IIdsCursorQueryResultDTO>(query, cursor : cursor).ToArray();
    }

    if (results.Any())
    {
        nextCursor = results.Last().NextCursor;
    }
    else
    {
        nextCursor = -1;
    }

    return results;
}

// Main method iterating to get all the available follower idsstaticvoid Main()
{
    RateLimit.RateLimitTrackerOption = RateLimitTrackerOptions.TrackOnly;

    var followerIds = new List<long>();
    long nextCursor = -1;

    do
    {
        var firstBatchOfFollowerIds = GetFollowerIds("shakira", nextCursor, out nextCursor);
        followerIds.AddRange(firstBatchOfFollowerIds.SelectMany(x => x.Ids));
    } 
    while (nextCursor != -1);
}

Viewing all articles
Browse latest Browse all 4126

Trending Articles



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