I have a twitter bot that uses LinqtoTwitter it works perfectly fine but when i start it after almost 20 reply(comment) on other users tweets the token gets expired without any warning. I changed the intervals from every 5 min to every 10 minutes still the tokens get disappeared and i need to generate a new token!!
This app sends product links to users based on their tweets it is web based and runs background thread so once it is running it is working in the background even if closing the web page How can I fix this issue?! And now the app got suspended :( not the user tho! Here is the auth code:
private static string consumer_Key = ConfigurationManager.AppSettings["consumerkey"];
private static string consumer_Key_Secret = ConfigurationManager.AppSettings["consumersecret"];
private static string access_Token = ConfigurationManager.AppSettings["accessToken"];
private static string access_Token_Secret = ConfigurationManager.AppSettings["accessTokenSecret"];
static SingleUserAuthorizer auth = new SingleUserAuthorizer
{
CredentialStore = new SingleUserInMemoryCredentialStore
{
ConsumerKey = consumer_Key,
ConsumerSecret = consumer_Key_Secret,
AccessToken = access_Token,
AccessTokenSecret = access_Token_Secret,
}
};
A common issue with Web apps is that the Web server (IIS) recycles occasionally and any credentials held in memory are lost. One of the things you can do is to use a
SessionStateCredentialStore, like this:To overcome the recycling problem, make sure your session state is set to
StateServiceorSqlServer, rather thanInProc.Another option is to verify that you still have credentials loaded before performing an operation. The
CredentialStorehas aHasAllCredentialsmethod you can use like this.If you're running into capacity problems where Twitter is sending you rate limit errors, consider the
ApplicationOnlyAuthorizer, which gives you a larger rate limit. If you go withApplicationOnlyAuthorizer, my comments on credentials above still apply.You can use
try/catchblocks to detect when you've exceeded rate limit or use theTwitterContext.RateLimitXxxproperties to monitor each query to avoid exceeding the limits.If Twitter is revoking your credentials, you'll need to resolve that with them. That's an issue between the Twitter API and your application, not LINQ to Twitter.