我正在使用Tweetinvi 4.0.3和.NET 4.7.2。我做了一个新的项目,我只是试着让Twitter和我的桌面应用程序一起工作。我正在使用来自wiki的Tweetinvi示例,但是它引发了一个异常:
System.NullReferenceException:“对象引用未设置为对象的实例。”
因为authenticationContext从AuthFlow.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?
发布于 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;。来源
希望这对将来的其他人有帮助。
https://stackoverflow.com/questions/63570115
复制相似问题