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

New Post: errors retrieving IUsers list from ID

$
0
0
Hi,

I am aware that this limitation is pretty complicated to cope with. Trust me I had to face the same problem.
You do not really have a choice, Twitter Limits the access to the Followers to 15 per 15 minutes (twitter documentation).

When I was doing research we had to use multiple tokens in order to cope with this limitation.
But be aware that I don't think this is in line with Twitter Policy (but there is no other way).

Here is a Work Item that will add this feature but I don't think I will implement it in either 0.9.6.x or 0.9.7.x.

If you want to use multiple tokens here is what you can do :
  • Create a List of IOAuthCredentials
  • Before the query is executed look at your set of credentials and select the one that is going to be reset the soonest
  • If none of your credentials have remaining available operation wait for the soonest available credentials.
  • Otherwise use the soonest refreshed credentials to perform your operations
Please note that the following code will only work with the Source Code version (0.9.6.0) as I have made improvements to the RateLimits.

There are quite few lines of code but they are not complicated to understand.
List<IOAuthCredentials> credentials = new List<IOAuthCredentials>() { /* Add your multiple credentials */};
TweetinviEvents.QueryBeforeExecute += (sender, args) =>
{
    var rateLimits = RateLimit.GetQueryRateLimit(args.QueryURL);
    if (rateLimits == null)
    {
        // RateLimit cannot be identified for the queryreturn;
    }

    if (rateLimits.Remaining > 0)
    {
        // We can continue to perform queries with the current credentialsreturn;
    }

    if (!credentials.Any())
    {
        // If no credentials have been setup, we have to wait
        RateLimit.AwaitForQueryRateLimit(rateLimits);
        return;
    }

    var credentialsAssociatedWithQueryRateLimit = new Dictionary<ITokenRateLimit, IOAuthCredentials>();
    foreach (var credential in credentials)
    {
        var tokenRateLimits = RateLimit.GetQueryRateLimit(args.QueryURL, credential);
        credentialsAssociatedWithQueryRateLimit.Add(tokenRateLimits, credential);
    }

    var allCredentials = credentialsAssociatedWithQueryRateLimit.Keys;
    var credentialsThatCanBeUsed = allCredentials.Where(x => x.Remaining > 0);

    var earliestAvailableRateLimit = GetEarliestAvailableRateLimit(allCredentials);
    var associatedCredentials = credentialsAssociatedWithQueryRateLimit[earliestAvailableRateLimit];

    if (!credentialsThatCanBeUsed.Any()) // There are no credentials with any remaining token for the query
    {
        // Await for the credentials that will be available the soonest
        RateLimit.AwaitForQueryRateLimit(args.QueryURL, associatedCredentials);
        return;
    }

    // We want to use the working credentials for the coming query
    TwitterCredentials.SetCredentials(associatedCredentials);
};
In your case, as you use ExecuteOperationWithCredentials you will have to replace the last line of code so that it updates your 'cred' variable.

Regards,
Linvi

Viewing all articles
Browse latest Browse all 4126

Trending Articles



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