I’ve been building a project using Twitter4J, the problem is that don’t matter where I try to run this code it always use my Twitter account to authenticate and worst: It doesn’t authenticate. When I open the script it has already authenticated with my account without asking me to accept or not. This is the code I’m using:
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("********")
.setOAuthConsumerSecret("****************************************")
.setOAuthAccessToken("***********************************************")
.setOAuthAccessTokenSecret("***************************************");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
What I’m doing wrong and how to correct it?
Are you using this code to authentication only or for making other api calls?
You don’t need to set access token and token secret, if you need to authenticate an new user. It have to use only consumer’s key/secret there. (Then prepare new callback url, redirect user, etc, etc)
Access token is used when you are requesting other data from twitter api, for specified user (connected to this accestoken).
And also, note that twitter authentication gives you credentials of currently logged in user. I mean user that already logged into twitter. And also it ask him only once – when he tries to authenticate first time, at second time it will reuse it.