基本上,我想做的是从用户那里获取最新的tweet并对其进行处理。我正在使用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。那么,如何保存我的凭据,而不必在每次启动时都重新连接?
最佳答案
我是Tweetinvi的主要开发人员。
如果存储了4个凭据信息,则可以将其与2种不同的解决方案重复使用:
Auth.SetUserCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
// OR
var creds = new TwitterCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
Auth.SetCredentials(creds);
该文档可能会帮助您设置应用程序:https://github.com/linvi/tweetinvi/wiki/Introduction