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

New Post: Cursor Queries and API Limit

$
0
0
Thanks for the link. :)

I came up with the following solution.
var screenName = "ladygaga";
int maxObjectsToRetrieve = 1000000;
var followerQuery = String.Format("https://api.twitter.com/1.1/followers/ids.json?screen_name={0}&count=5000", screenName);
List<long> scrapedIds = new List<long>();
long cursor = -1;
do
{
    var result = TwitterAccessor.ExecuteCursorGETQuery<IIdsCursorQueryResultDTO>(followerQuery, maxObjectsToRetrieve, cursor);
    if (result != null)
    {
        var ids = result.SelectMany(x => x.Ids);
        scrapedIds.AddRange(ids);
        cursor = result.Select(x => x.NextCursor).LastOrDefault();
    }

    var timeToWait = RateLimit.GetCurrentCredentialsRateLimits().FollowersIdsLimit.ResetDateTime - DateTime.Now;
    Debug.WriteLine("waiting for {0}...", timeToWait);
    Thread.Sleep(timeToWait);
} while (scrapedIds.Count < maxObjectsToRetrieve && cursor != 0);
Console.WriteLine("{0} ids found.", scrapeIds.Count);
Lokesh

Viewing all articles
Browse latest Browse all 4126

Trending Articles



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