我一直在使用Linq2Twitter(v. 2),使用搜索API和我想切换到流 API。我更新到 v. 3,但从那时起我就无法再进行身份验证了。我不认为 Stream API 或版本可能是问题所在,因为我试图回到以前的版本、以前的身份验证方法,但它也不再起作用了。我得到一个401 : bad authentication data.
所以,这是我当前的代码:
var auth = new SingleUserAuthorizer
{
CredentialStore = new SingleUserInMemoryCredentialStore()
{
ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"],
OAuthToken = ConfigurationManager.AppSettings["twitterOAuthToken"],
AccessToken = ConfigurationManager.AppSettings["twitterAccessToken"]
}
};
TwitterContext _twitterCtx = new TwitterContext(auth);
try
{
var verifyResponse =
await
(from acct in _twitterCtx.Account
where acct.Type == AccountType.VerifyCredentials
select acct)
.SingleOrDefaultAsync();
if (verifyResponse != null && verifyResponse.User != null)
{
User user = verifyResponse.User;
Console.WriteLine(
"Credentials are good for {0}.",
user.ScreenNameResponse);
}
}
catch (TwitterQueryException tqe)
{
Console.WriteLine(tqe.Message);
}
当然,我检查了几次凭据,将它们打印出来等等。我也尝试使用ApplicationOnlyAuthorizer,v.2,v.3,它不会改变任何东西。最让我害怕的是,过去有效的方法(v2 + ApplicationOnly + Search API)也不起作用。
通过我的研究,我听说过由不同步时间戳或类似问题引起的问题。但我不明白我该如何改变这一点。该程序不在服务器上,而是本地存储的。
感谢您的阅读。
v3.0 中使用 SingleUserAuthorizer 的方法:
var auth = new SingleUserAuthorizer
{
CredentialStore = new SingleUserInMemoryCredentialStore
{
ConsumerKey = ConfigurationManager.AppSettings["consumerKey"],
ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"],
AccessToken = ConfigurationManager.AppSettings["accessToken"],
AccessTokenSecret = ConfigurationManager.AppSettings["accessTokenSecret"]
}
};
请注意,我在这里设置了 AccessToken 和 AccessToken 机密。我还有一个常见问题解答,其中包含解决 401 问题的建议:
https://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20FAQ&referringTitle=Documentation