【问题标题】:Tweetinvi authenticationContext returns nullTweetinvi authenticationContext 返回 null
【发布时间】:2020-12-13 15:06:34
【问题描述】:

我正在使用 Tweetinvi 4.0.3 和 .NET 4.7.2。我做了一个新项目,我只是在测试以尝试让 Twitter 与我的桌面应用程序一起工作。我正在使用来自 wiki 的 Tweetinvi 示例,但它引发了异常:

System.NullReferenceException: '对象引用未设置为对象的实例。'

因为 authenticationContextAuthFlow.InitAuthentication(appCredentials); 返回 null

这是我的代码:

private void Button1_Click(object sender, EventArgs e)
{
    // Create a new set of credentials for the application.
    var appCredentials = new TwitterCredentials(ConsumerKey, ConsumerSecret);

    // Init the authentication process and store the related `AuthenticationContext`.
    var authenticationContext = AuthFlow.InitAuthentication(appCredentials);

    // Go to the URL so that Twitter authenticates the user and gives him a PIN code.
    Process.Start(authenticationContext.AuthorizationURL);

    // Ask the user to enter the pin code given by Twitter
    var pinCode = Console.ReadLine();

    // With this pin code it is now possible to get the credentials back from Twitter
    var userCredentials = AuthFlow.CreateCredentialsFromVerifierCode(pinCode, authenticationContext);

    // Use the user credentials in your application
    Auth.SetCredentials(userCredentials);
}

知道我需要做些什么来完成这项工作吗?我读过一些关于回调 URL 的内容,但它是一个桌面应用程序,所以我没有回调 URL?

【问题讨论】:

    标签: c# tweetinvi


    【解决方案1】:

    经过大量时间,我能够找出问题所在。我猜 Twitter 现在需要 TLS 1.2,如下所述:https://api.twitterstat.us/(向下滚动以更新 25/7/2019)。将我的 .NET Framewokr 升级到 4.6(从 4.0)解决了这个问题。

    我在其他地方看到你可以使用System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;Source

    希望这对将来的其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 2019-12-25
      • 2017-05-21
      • 1970-01-01
      • 2020-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-21
      • 2021-03-11
      相关资源
      最近更新 更多