LinqToTwitter状态更新有时才有效
本文关键字:有效 状态 更新 LinqToTwitter | 更新日期: 2023-09-27 18:02:07
我正在尝试使用LinqToTwitter
发送tweet。我的问题是,它几乎从来都不起作用。我已经让它在30次中运行了3次,通常这是我尝试调试的时候。我认为这可能与时间和身份验证有关,但我不知道怎么做。代码运行时没有错误,但不会生成tweet。
public static async Task SendTweetAsync(string text)
{
// Get the authorization credentials
var auth = GetCredentials();
// Create the twitter context
var ctx = new TwitterContext(auth);
try
{
Status responseTweet = await ctx.TweetAsync(text);
}
catch (Exception e) {
throw e;
}
}
private static AspNetAuthorizer GetCredentials()
{
return new AspNetAuthorizer
{
CredentialStore = new InMemoryCredentialStore()
{
ConsumerSecret = "##########",
ConsumerKey = "##########",
OAuthToken = "##########",
OAuthTokenSecret = "##########",
UserID = ##########
}
};
}
我不知道之前在这里的答案发生了什么,由@JoeMayo,但对我有用的是将AspNetAuthorizer
更改为SingleUserAuthorizer
。
private static SingleUserAuthorizer GetCredentials()
{
return new SingleUserAuthorizer
{
CredentialStore = new InMemoryCredentialStore()
{
ConsumerSecret = "##########",
ConsumerKey = "##########",
OAuthToken = "##########",
OAuthTokenSecret = "##########",
UserID = ##########
}
};
}
我还添加了await auth.AuthorizeAsync();
var auth = GetCredentials();
await auth.AuthorizeAsync();
就像我说的,功劳应该归@JoeMayo,但是他的答案不见了