【发布时间】:2020-12-13 15:06:34
【问题描述】:
我正在使用 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?
【问题讨论】: