LinqToTwitter I can't catch tweets

150 Views Asked by At

I am trying to fetch tweets using the example on GitHub, but I get an error "The underlying connection was closed: An unexpected error occurred in a submission". I can not understand. At first, I created the application on Twitter and took the keys generated by Twitter and added it to the application. I had doubts about 2 attributes that I don't know what they will be used for, and I don't know if they are causing problems:

1 - Website URL - I created a website on Wix to fill this field, but I didn't understand its use, since I just want to read tweets in a desktop application.

2 - Callback URL - Initially I didn't put anything, then I saw in a post that it was to put http://127.0.0.1/ I ran the application with this information, but again I don't know what it is for, because I'm going to get tweets from a desktop application .

Here are the code used and the error received!


using System;
using System.Linq;
using System.Threading.Tasks;
using LinqToTwitter;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main()
        {        
            MainAsync().Wait();
        }
        static async Task MainAsync()
        {
            var auth = new SingleUserAuthorizer
            {

                CredentialStore = new InMemoryCredentialStore()
                {
                    ConsumerKey = "MyConsumerKey",
                    ConsumerSecret = "MyConsumerSecret",
                    OAuthToken = "MYOAuthToken",
                    OAuthTokenSecret = "MYOAuthTokenSecret"
                }
            };
            var twitterCtx = new TwitterContext(auth);

            var searchResponse = await (from search in twitterCtx.Search
                                        where search.Type == SearchType.Search 
                                        &&  search.Query == "flamengo"
                                        select search).SingleOrDefaultAsync();

            if (searchResponse != null && searchResponse.Statuses != null)
                searchResponse.Statuses.ForEach(tweet =>
                    Console.WriteLine(
                        "User: {0}, Tweet: {1}",
                        tweet.User.ScreenNameResponse,
                        tweet.Text));
        }
    }
}


System.AggregateException was unhandled
  HResult=-2146233088
  Message=Um ou mais erros.
  Source=mscorlib
  StackTrace:
       em System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
       em System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
       em System.Threading.Tasks.Task.Wait()
       em ConsoleApplication3.Program.Main() na C:\Danilo\Docs\Visual Studio 2015\Projects\ConsoleApplication3\ConsoleApplication3\Program.cs:linha 12
       em System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       em System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       em Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       em System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       em System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       em System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
       HResult=-2146233088
       Message=Ocorreu um erro ao enviar a solicitação.
       Source=mscorlib
       StackTrace:
            em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            em LinqToTwitter.Net.GetMessageHandler.<SendAsync>d__4.MoveNext()
         --- Fim do rastreamento de pilha do local anterior onde a exceção foi gerada ---
            em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            em LinqToTwitter.TwitterExecute.<QueryTwitterAsync>d__48 1.MoveNext()
         --- Fim do rastreamento de pilha do local anterior onde a exceção foi gerada ---
            em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            em LinqToTwitter.TwitterContext.<ExecuteAsync>d__136 1.MoveNext()
         --- Fim do rastreamento de pilha do local anterior onde a exceção foi gerada ---
            em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            em LinqToTwitter.TwitterQueryProvider.<ExecuteAsync>d__8 1.MoveNext()
         --- Fim do rastreamento de pilha do local anterior onde a exceção foi gerada ---
            em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            em LinqToTwitter.TwitterExtensions.<SingleOrDefaultAsync>d__5 1.MoveNext()
         --- Fim do rastreamento de pilha do local anterior onde a exceção foi gerada ---
            em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
            em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
            em System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
            em ConsoleApplication3.Program.<MainAsync>d__1.MoveNext() na C:\Danilo\Docs\Visual Studio 2015\Projects\ConsoleApplication3\ConsoleApplication3\Program.cs:linha 29
       InnerException: 
            HResult=-2146233079
            Message=A conexão subjacente estava fechada: Erro inesperado em um envio.
            Source=System
            StackTrace:
                 em System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
                 em System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar)
            InnerException: 
                 HResult=-2146232800
                 Message=Não é possível ler os dados da conexão de transporte: Foi forçado o cancelamento de uma conexão existente pelo host remoto.
                 Source=System
                 StackTrace:
                      em System.Net.TlsStream.EndWrite(IAsyncResult asyncResult)
                      em System.Net.PooledStream.EndWrite(IAsyncResult asyncResult)
                      em System.Net.ConnectStream.WriteHeadersCallback(IAsyncResult ar)
                 InnerException: 
                      ErrorCode=10054
                      HResult=-2147467259
                      Message=Foi forçado o cancelamento de uma conexão existente pelo host remoto
                      NativeErrorCode=10054
                      Source=System
                      StackTrace:
                           em System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
                           em System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
                      InnerException:

1

There are 1 best solutions below

0
Joe Mayo On BEST ANSWER

This looks similar to the question we resolved here, where the problem was needing to set to TLS 1.2 because it was an older .NET version:

Visual Studio 2015 - Debug with HTTP connection problems