LinqToTwitter 我无法捕捉推文

LinqToTwitter I can't catch tweets

我正在尝试使用 GitHub 上的示例获取推文,但出现错误 "The underlying connection was closed: An unexpected error occurred in a submission"。我无法理解。起初,我在 Twitter 上创建了应用程序,并将 Twitter 生成的密钥添加到应用程序中。我对2个属性有疑问,我不知道它们将用于什么,我不知道它们是否会导致问题:

1 - 网站 URL - 我在 Wix 上创建了一个网站来填写这个字段,但我不明白它的用途,因为我只想在桌面应用程序中阅读推文。

2 - 回调 URL - 最初我什么都没放,然后我在一个 post 中看到它是把 http://127.0.0.1/ 我 运行 应用程序有了这些信息,但我还是不知道它的用途,因为我要从桌面应用程序获取推文。

这是使用的代码和收到的错误!


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:

这看起来与我们在此处解决的问题类似,该问题需要设置为 TLS 1.2,因为它是较旧的 .NET 版本: