Cursor Queries and API Limit

Editor
Mar 18, 2014 at 1:11 PM
Hi Linvi,

I see that tweetinvi automatically handles the cursor parameter. However, if I want to do something like this:
var users = User.GetFollowerIds("screenname", 100000);
Then it will only return the first 75000 ids as it hits the api limit with that number. I was wondering if there's any way to go past 75000?

I dont know if there's a way to already do that but I have an idea.

Maybe if you allow us to pass a cursorId parameter into functions that use cursor queries, we can extract the cursor id from last exception's URL and use it to continue the app after suitably waiting for the rate limit to reset.

Thank you for your time.
Lokesh
Coordinator
Mar 18, 2014 at 3:27 PM
Hi,

I currently do not provide such feature because I want the api to be simple to use and not have 5 optional parameters.
This feature will be implemented in later versions but in the meantime I invite you to read the 2 responses of this post : https://tweetinvi.codeplex.com/discussions/538201.

Linvi
Editor
Mar 18, 2014 at 8:36 PM
Edited Mar 19, 2014 at 11:34 AM
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
Marked as answer by linvi on 3/18/2014 at 1:22 PM