RateLimit.GetQueryRateLimit(args.QueryURL) is null
See original GitHub issueHi Linvi,
I’m using TweetinviEvents.QueryBeforeExecute to check whether the next request is rate limited or not. I noticed two strange behaviours:
- QueryBeforeExecute is called more times or wasn’t even called when i executed the request
- RateLimit.GetQueryRateLimit(args.QueryURL) returns null after around 100 same requests (though there are still a lot left) Can you check please my code below?
Regards, Levente
private static void InitializeTweetinviConfig(bool isApp = false)
{
ExceptionHandler.SwallowWebExceptions = false;
// use of multiple twitter apps
_isApp = isApp;
RateLimit.RateLimitTrackerMode = RateLimitTrackerMode.TrackOnly;
TweetinviConfig.ApplicationSettings.TweetMode = TweetMode.Extended;
}
private void InitializeTweetinviConfigWithAuth(string accessToken, string accessTokenSecret, bool isApp = false)
{
InitializeTweetinviConfig(isApp);
// i have tried with and without clear cache
// RateLimit.ClearRateLimitCache();
TweetinviEvents.CurrentThreadEvents.QueryBeforeExecute += (sender, args) =>
{
var rateLimits = RateLimit.GetQueryRateLimit(args.QueryURL);
if (rateLimits != null)
{
if (rateLimits.Remaining > 0)
{
// We have enough resource to execute the query
return;
}
}
else
{
return;
}
// it's code it wasn't reached cuz rateLimits was null
var shouldChangeCredentials = _isApp;
if (shouldChangeCredentials)
{
//if it's app request, loop through all customer credentials until find one that are not rate limited
foreach (var item in _alternativeTwitterCustomerCreds)
{
var alternativeCredential = Auth.SetApplicationOnlyCredentials(item.Key, item.Value, true);
var alternativeQueryRateLimits = RateLimit.GetQueryRateLimit(args.QueryURL, alternativeCredential);
if (alternativeQueryRateLimits != null)
{
if (alternativeQueryRateLimits.Remaining > 0)
{
args.TwitterQuery.TwitterCredentials = alternativeCredential;
return;
}
}
}
}
};
Auth.SetUserCredentials(_consumerKey, _consumerSecret, accessToken, accessTokenSecret);
}
public async Task<List<ITweet>> GetPosts(string accessToken, string accessTokenSecret, List<long> postIds)
{
return await Sync.ExecuteTaskAsync(() =>
{
InitializeTweetinviConfigWithAuth(accessToken, accessTokenSecret, true);
return Tweet.GetTweets(postIds.ToArray()).ToList();
});
}
//test api endpoint, for testing rate limit
[HttpGet]
public async Task<IHttpActionResult> GetTwitterPostsByIds()
{
string accessToken = "-------------------------";
string accessTokenSecret = "-------------------------";
List<long> ids = new List<long>() { 771698365948100608,
779297282642542593,
779313850462113792 };
for (int i = 0; i < 1000; i++)
{
List<ITweet> tweets = await _twitterService.GetPosts(accessToken, accessTokenSecret, ids);
}
return Ok();
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
ratelimit tracking issue #381 - linvi/tweetinvi
i tried to search tweets using ur method to deal with rate limit but there is ... GetQueryRateLimit(args. ... if (queryRateLimits != null)...
Read more >Is there a way to "notify" when you hit the hourly limit?
QueryBeforeExecute += (sender, args) => { var queryRateLimit = RateLimit.GetQueryRateLimit(args.QueryURL); if (queryRateLimit != null) { if ...
Read more >TweetInvi - Cannot Unfollow Users
GetQueryRateLimit (args.QueryURL); // Some methods are not RateLimited. Invoking such a method will result in the queryRateLimits to be null ...
Read more >Tweetinvi a friendly Twitter C# library - RSSing.com
If the credentials are set to null, the CurrentThreadCredentials will be used; if they have not been set either, an exception will be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I will be looking into it as part of the next release. I will provide some feedback as quickly as possible.
@linvi I am still having issue, so i started catching exception using manual exception.