【问题标题】:Saving Tweetinvi credentials without re-authenticating every time无需每次都重新验证即可保存 Tweetinvi 凭据
【发布时间】:2016-08-02 15:35:25
【问题描述】:

基本上,我想要做的是从用户那里获取最近的推文并与他们一起做事。我正在使用基于 PIN 的身份验证的 Tweetinvi,如网站上所述,如下所示:

// 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。那么如何保存我的凭据,这样我就不必在每次启动时重新连接?

【问题讨论】:

  • 我提供的解决方案好运吗?
  • @Linvi 现在可以正常工作了,谢谢

标签: c# twitter tweetinvi


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-09
    • 2020-02-16
    • 2019-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 1970-01-01
    相关资源
    最近更新 更多