Authentication details missing or incorrect


This is my code:

package com.tyluur;

import java.util.ArrayList;

import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.auth.AccessToken;

public class Main {
	private static ArrayList<Account> accountList = new ArrayList<Account>();
	private final static String CONSUMER_KEY = "XXX";
	private final static String CONSUMER_KEY_SECRET = "XXXX";
	public static void main(String[] args) throws IOException, TwitterException {
		for (Account account : accountList) {
			Twitter twitter = TwitterFactory.getSingleton();
			twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_KEY_SECRET);
			twitter.setOAuthAccessToken(new AccessToken(account.getName(), account.getPassword()));

	private static void loadAccounts() throws IOException {
		for (String lines : FileUtilities.readFile("accounts.txt")) {
			String[] accountSplit = lines.split(":");
			accountList.add(new Account(accountSplit[0], accountSplit[1]));


I’m getting this error:

Exception in thread “main” 401:Authentication credentials ( were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
message - Invalid or expired token
code - 89

Relevant discussions can be found on the Internet at: or
TwitterException{exceptionCode=[d8646c05-05d7fa55], statusCode=401, message=Invalid or expired token, code=89, retryAfter=-1, rateLimitStatus=null, version=3.0.3}
at twitter4j.internal.http.HttpClientImpl.request(
at twitter4j.internal.http.HttpClientWrapper.request(
at twitter4j.internal.http.HttpClientWrapper.get(
at twitter4j.TwitterBaseImpl.fillInIDAndScreenName(
at twitter4j.TwitterBaseImpl.getScreenName(
at com.tyluur.Main.main(


In the future, be a bit more careful about posting your credentials to a public forum.

twitter4j hides the true nature of these errors from you. Try to get ahold of the actual response body for a better hint as to what’s going wrong.

In this case, it looks like you’re trying to access a resource with an access token you haven’t yet negotiated or are leveraging.


thanks indeed