Closed shepherd324 closed 4 years ago
This is interesting. You should receive a TwitterException
as the next operation should fail.
I am assuming you are not using a RateLimit handler at the moment.
Would you mind sharing the exception that you are receiving?
I have actually tested this code and I did receive a TwitterException
with 429 status code.
Do we agree that that the code where you put ...
is failing because of Tweetinvi?
This is the code you should be using.
while (!friendsIterator.Completed)
{
await friendsIterator.NextPageAsync();
}
Some additional details:
Here is the additional code in the ... block:
try {
var friendsIterator = userClient.Users.GetFriendsIterator(new GetFriendsParameters(handle));
while (!friendsIterator.Completed)
{
var page = friendsIterator.NextPageAsync().Result;
foreach(var item in page.Items)
{
//do other things, no additional Tweetinvi calls
}
}
}
catch(TwitterException e) {
//this does not get hit
}
catch(Exception e) {
//this gets hit
}
Here is the full exception I am getting:
"System.AggregateException: One or more errors occurred. (Reason : Too Many Requests Details : Rate limit exceeded (88) Code : 429 Date : 11/24/2020 1:59:01 PM -06:00 URL : https://api.twitter.com/1.1/friends/ids.json?screen_name=xxx&count=5000 Twitter documentation description : Too Many Requests - Returned in API v1.1 when a request cannot be served due to the application's rate limit having been exhausted for the resource. See Rate Limiting in API v1.1. ) ---> Reason : Too Many Requests Details : Rate limit exceeded (88) Code : 429 Date : 11/24/2020 1:59:01 PM -06:00 URL : https://api.twitter.com/1.1/friends/ids.json?screen_name=xxx&count=5000 Twitter documentation description : Too Many Requests - Returned in API v1.1 when a request cannot be served due to the application's rate limit having been exhausted for the resource. See Rate Limiting in API v1.1.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExcept
ional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task
1.get_Result()
at GMRInfluencerFinder.Program.Run() in //Program.cs
Thank you for sharing your code. The issues comes from your .Result
.
async
operations expect await
to be used for exception handling.
If you wish to use .Result
you will need to use the following code:
catch (AggregateException e)
{
if (e.InnerException is TwitterException twitterException)
{
System.Console.WriteLine(twitterException.Message);
}
}
Additionally I would highly suggest you use await
to prevent deadlocks in your application.
I am running GetFriendsIterator queries in a loop and upon hitting my rate limit a 429 exception is being thrown, however my catch handler for the TwitterException is not being hit. My understanding is that a TwitterException should be thrown in the event that rate limits are hit.