首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tweetinvi authenticationContext返回空

Tweetinvi authenticationContext返回空
EN

Stack Overflow用户
提问于 2020-08-24 23:48:19
回答 1查看 130关注 0票数 0

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

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

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

这是我的代码:

代码语言:javascript
复制
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?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-27 14:57:17

在花费了大量的时间之后,我终于解决了这个问题。我想推特现在需要TLS 1.2,如下所示:https://api.twitterstat.us/ (向下滚动到25/7/2019更新)。将我的.NET Framewokr升级到4.6 (从4.0)解决了这个问题。

我在其他地方读到过,你可以使用System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;来源

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63570115

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档