Having multiple Twitter instances with twitter4j library.
access-token, twitter, twitter-oauth, twitter4j
Solution
In short, you may want code like this:
TwitterFactory tf = new TwitterFactory();
Twitter user1 = tf.getInstance(new AccessToken("XXX","XXX"));
Twitter user2 = tf.getInstance(new AccessToken("XXX","XXX"));
A Twitter instance can handle only one account. To deal with multiple accounts, you need to instantiate multiple Twitter instances with TwitterFactory#getInstance(AccessToken);
Hard-coding consumer key/secret is not suggested and you may want to specify them in twitter4j.properties. http://twitter4j.org/en/configuration.html#fileconfiguration
Problem
I need to be able to make different `Twitter` instances with same consumer key and secret but different user level access tokens. I have already obtained the access tokens for 10 users based on consumer credentials of my app by using standard Twitter OAuth Sign In protocol. Now, I want to create a list of Twitter Instances each initialized with a separate `Accesstoken`. However, I'm not able to do this. My leading cause of confusion is, that, I don't understand how `Twitter4j` instantiates Twitter instances. I don't understand the difference between `TwitterFactory.getSingleton()` method and `TwitterFactory().getInstance()` method. I also don't understand if AccessTokens can work independently without supplying consumer key and secret. Or do I need to provide Consumer key and secret while using Accesstokens. If someone can explain in detail the design for my requirement it'll be highly appreciated.