This is my code:
package com.tyluur;
import java.io.IOException;
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 {
loadAccounts();
for (Account account : accountList) {
Twitter twitter = TwitterFactory.getSingleton();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_KEY_SECRET);
twitter.setOAuthAccessToken(new AccessToken(account.getName(), account.getPassword()));
System.out.println(twitter.getScreenName());
}
}
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 (https://dev.twitter.com/pages/auth) 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:
http://www.google.co.jp/search?q=d8646c05 or
http://www.google.co.jp/search?q=05d7fa55
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(HttpClientImpl.java:177)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:89)
at twitter4j.TwitterBaseImpl.fillInIDAndScreenName(TwitterBaseImpl.java:126)
at twitter4j.TwitterBaseImpl.getScreenName(TwitterBaseImpl.java:102)
at com.tyluur.Main.main(Main.java:26)