GetUserTimelineAsync throws exception

Jun 30, 2014 at 9:58 PM
Hi,

Great APIs! Just started using it to get timelines for about three or four handles. The call sequence looks like this:
  1. TwitterCredentials.SetCredentials(...);
  2. user = await UserAsync.GetUserFromScreenName(handle);
  3. timeline = await user.GetUserTimelineAsync(10);
  4. wait 30s, repeat 2. and 3. for next handle
The calls succeed in 1., 2., 3., 2., 3., 2., and fails usually on the second or third call to GetUserTimelineAsync(). The exception was thrown in Tweetinvi.WebLogic.DLL!Tweetinvi.WebLogic.WebHelper.GetWebResponse(), with the exception:

-2146233088
{System.Net.WebException: The remote server returned an error: NotFound...

I reordered the handles and it fails for different handles but usually on the second or third time it's called, so it doesn't seem to be handle-dependent. From that point on all calls would fail.

Questions:
  1. Am I not using the APIs correctly?
  2. If not, what are the possible causes and solutions?
Thanks in advance.
Coordinator
Jul 7, 2014 at 11:13 PM
Hi,

No you are using the api correctly, I am not sure what you are doing incorrectly.
Would you please let me know which error do you receive?
ExceptionHandler.GetLastException();
Regards,
Linvi
Jul 8, 2014 at 6:07 AM
Thanks for your response. The first exception that is thrown is an AggregateException, with the inner exception being the WebException above.

stack:
[External Code]
Tweetinvi.WebLogic.DLL!Tweetinvi.WebLogic.WebHelper.GetWebResponse(System.Net.WebRequest webRequest) Line 34 C#
Tweetinvi.WebLogic.DLL!Tweetinvi.WebLogic.WebRequestExecutor.ExecuteWebRequest(System.Net.HttpWebRequest httpWebRequest) Line 36 C#
Tweetinvi.WebLogic.DLL!Tweetinvi.WebLogic.TwitterRequester.ExecuteQuery(string url, Tweetinvi.Core.Enum.HttpMethod httpMethod, System.Collections.Generic.IEnumerable<Tweetinvi.Core.Interfaces.oAuth.IOAuthQueryParameter> headers) Line 24 C#
Tweetinvi.Credentials.DLL!Tweetinvi.Credentials.TwitterAccessor.ExecuteQuery(string query, Tweetinvi.Core.Enum.HttpMethod method) Line 298 C#
Tweetinvi.Credentials.DLL!Tweetinvi.Credentials.TwitterAccessor.ExecuteGETQuery<System.Collections.Generic.IEnumerable<Tweetinvi.Core.Interfaces.DTO.ITweetDTO>>(string query, Newtonsoft.Json.JsonConverter[] converters) Line 98 C#
Tweetinvi.Controllers.DLL!Tweetinvi.Controllers.Timeline.TimelineQueryExecutor.GetUserTimeline(Tweetinvi.Core.Interfaces.Models.Parameters.IUserTimelineRequestParameters timelineRequestParameters) Line 44 C#
Tweetinvi.Controllers.DLL!Tweetinvi.Controllers.Timeline.TimelineController.GetUserTimeline(Tweetinvi.Core.Interfaces.Models.Parameters.IUserTimelineRequestParameters timelineRequestParameters) Line 80 C#
Tweetinvi.Controllers.DLL!Tweetinvi.Controllers.Timeline.TimelineController.GetUserTimeline(Tweetinvi.Core.Interfaces.Models.IUserIdentifier userIdentifier, int maximumNumberOfTweets) Line 63 C#
Tweetinvi.Logic.DLL!Tweetinvi.Logic.User.GetUserTimeline(int maximumNumberOfTweets) Line 330 C#
Tweetinvi.Logic.DLL!Tweetinvi.Logic.User.GetUserTimelineAsync.AnonymousMethod__1e() Line 399 C#
[External Code]

When it gets back to my code:
        var timeline = await handle.User.GetUserTimelineAsync(10);

        if (timeline == null)
        {
            var lastException = ExceptionHandler.GetLastException();
        }
__I get a return value of null and the lastException is also null.

The output from the Output window:__

GET : https://api.twitter.com/1.1/users/show.json?screen_name=@XXXXXXXX
Header OAuth oauth_nonce="1234567",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1234567890",oauth_version="1.0",oauth_signature=XXXXXXXXXXXXXXXXXXXXXXXXX"
A first chance exception of type 'System.AggregateException' occurred in mscorlib.ni.dll
A first chance exception of type 'Tweetinvi.Logic.Exceptions.TwitterException' occurred in Tweetinvi.WebLogic.DLL
---- DEBUG ASSERTION FAILED ----
---- Assert Short Message ----

---- Assert Long Message ----
at <LoadTwitterHandle>d__c.MoveNext()  
at MoveNextRunner.InvokeMoveNext(Object stateMachine)  
at ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
at MoveNextRunner.Run()  
at <>c__DisplayClass1.<OutputWaitEtwEvents>b__0()  
at ContinuationWrapper.Invoke()  
at AwaitTaskContinuation.RunOrScheduleAction(Action action, Boolean allowInlining, Task& currentTask)  
at Task.FinishContinuations()  
at Task.FinishStageThree()  
at Task`1.TrySetResult(TResult result)  
at AsyncTaskMethodBuilder`1.SetResult(TResult result)  
at <GetUserFromScreenName>d__14.MoveNext()  
at MoveNextRunner.InvokeMoveNext(Object stateMachine)  
at ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
at MoveNextRunner.Run()  
at TaskAwaiter.RunNoException(Action continuation)  
at <>c__DisplayClassa.<OnCompletedInternal>b__4(Task param0)  
at ContinuationTaskFromTask.InnerInvoke()  
at Task.Execute()  
at Task.ExecutionContextCallback(Object obj)  
at ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
at Task.ExecuteWithThreadLocal(Task& currentTaskSlot)  
at Task.ExecuteEntry(Boolean bPreventDoubleExecution)  
at ThreadPoolTaskScheduler.TryExecuteTaskInline(Task task, Boolean taskWasPreviouslyQueued)  
at TaskScheduler.TryRunInline(Task task, Boolean taskWasPreviouslyQueued)  
at TaskContinuation.InlineIfPossibleOrElseQueue(Task task, Boolean needsProtection)  
at StandardTaskContinuation.Run(Task completedTask, Boolean bCanInlineContinuationTask)  
at Task.FinishContinuations()  
at Task.FinishStageThree()  
at Task`1.TrySetResult(TResult result)  
at AsyncTaskMethodBuilder`1.SetResult(TResult result)  
at <ExecuteTaskAsync>d__a`1.MoveNext()  
at MoveNextRunner.InvokeMoveNext(Object stateMachine)  
at ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
at MoveNextRunner.Run()  
at TaskAwaiter.RunNoException(Action continuation)  
at <>c__DisplayClassa.<OnCompletedInternal>b__4(Task param0)  
at ContinuationTaskFromTask.InnerInvoke()  
at Task.Execute()  
at Task.ExecutionContextCallback(Object obj)  
at ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
at Task.ExecuteWithThreadLocal(Task& currentTaskSlot)  
at Task.ExecuteEntry(Boolean bPreventDoubleExecution)  
at ThreadPoolTaskScheduler.TryExecuteTaskInline(Task task, Boolean taskWasPreviouslyQueued)  
at TaskScheduler.TryRunInline(Task task, Boolean taskWasPreviouslyQueued)  
at TaskContinuation.InlineIfPossibleOrElseQueue(Task task, Boolean needsProtection)  
at StandardTaskContinuation.Run(Task completedTask, Boolean bCanInlineContinuationTask)  
at Task.FinishContinuations()  
at Task.FinishStageThree()  
at Task`1.TrySetResult(TResult result)  
at AsyncTaskMethodBuilder`1.SetResult(TResult result)  
at <ExecuteTaskAsync>d__3`1.MoveNext()  
at MoveNextRunner.InvokeMoveNext(Object stateMachine)  
at ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
at MoveNextRunner.Run()  
at TaskAwaiter.RunNoException(Action continuation)  
at <>c__DisplayClassa.<OnCompletedInternal>b__4(Task param0)  
at ContinuationTaskFromTask.InnerInvoke()  
at Task.Execute()  
at Task.ExecutionContextCallback(Object obj)  
at ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)  
at Task.ExecuteWithThreadLocal(Task& currentTaskSlot)  
at Task.ExecuteEntry(Boolean bPreventDoubleExecution)  
at ThreadPoolTaskScheduler.TryExecuteTaskInline(Task task, Boolean taskWasPreviouslyQueued)  
at TaskScheduler.TryRunInline(Task task, Boolean taskWasPreviouslyQueued)  
at TaskContinuation.InlineIfPossibleOrElseQueue(Task task, Boolean needsProtection)  
at StandardTaskContinuation.Run(Task completedTask, Boolean bCanInlineContinuationTask)  
at Task.FinishContinuations()  
at Task.FinishStageThree()  
at Task.FinishStageTwo()  
at Task.Finish(Boolean bUserDelegateExecuted)  
at Task.ExecuteWithThreadLocal(Task& currentTaskSlot)  
at Task.ExecuteEntry(Boolean bPreventDoubleExecution)  
at Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()  
at ThreadPoolWorkQueue.Dispatch()  
at _ThreadPoolWaitCallback.PerformWaitCallback()  
Any help is appreciated.
Jul 8, 2014 at 6:37 AM
I did notice that the calls that fail don't have the key and token in the header:

Works:
GET : https://api.twitter.com/1.1/users/show.json?screen_name=@AAAAAAA
Header OAuth oauth_consumer_key="XXXXXXXXXXXXXXXX",oauth_nonce="11111111",oauth_signature_method="HMAC-SHA1",oauth_timestamp="11111111111",oauth_token="xxxxxxxxxxxxxxxxxxxxxxxx",oauth_version="1.0",oauth_signature="XXXXXXXXXXXXXXXXXX"

Works:
GET : https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=11111111&include_rts=True&exclude_replies=False&contributor_details=False&count=10&trim_user=False&include_entities=True
Header OAuth oauth_consumer_key="XXXXXXXXXXXXXX",oauth_nonce="111111111",oauth_signature_method="HMAC-SHA1",oauth_timestamp="111111111",oauth_token="xxxxxxxxxxxxxxxxxxxxxx",oauth_version="1.0",oauth_signature="XXXXXXXXXXXXXXXX"

Fails:
GET : https://api.twitter.com/1.1/users/show.json?screen_name=@BBBBBBB
Header OAuth oauth_nonce="1111111",oauth_signature_method="HMAC-SHA1",oauth_timestamp="111111111",oauth_version="1.0",oauth_signature="XXXXXXXXXXXX"