基本上我想做的是从用户那里获取最近的推文并与他们一起做事。我正在使用 Tweetinvi 和基于 PIN 的身份验证,如网站上所述,如下所示:
// Create a new set of credentials for the application
var appCredentials = new TwitterCredentials("CONSUMER_KEY", "CONSUMER_SECRET");
// Go to the URL so that Twitter authenticates the user and gives him a PIN code
var url = CredentialsCreator.GetAuthorizationURL(appCredentials);
// This line is an example, on how to make the user go on the URL
Process.Start(url);
// 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 = CredentialsCreator.GetCredentialsFromVerifierCode(pinCode, appCredentials);
// Use the user credentials in your application
Auth.SetCredentials(userCredentials);
现在的问题是,每次通过浏览器启动我的应用程序时,我都必须登录并连接到 Twitter,这有点烦人。我尝试将身份验证详细信息保存在文本文件(消费者密钥、消费者秘密、访问令牌、访问令牌秘密)中,然后将信息插入 appCredentials 和 userCredentials,但没有结果,因为我不断收到 TwitterNullCredentialsException。那么如何保存我的凭据,这样我就不必在每次启动时重新连接?