2

基本上我想做的是从用户那里获取最近的推文并与他们一起做事。我正在使用 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。那么如何保存我的凭据,这样我就不必在每次启动时重新连接?

4

1 回答 1

3

我是 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

于 2016-04-12T09:58:54.037 回答