Desired Behavior: Get Tweets of users from their userID's listed in a TXT file
Work/Research done beforehand: Note: I have attempted looking up this error message, and any associated with the classes used in my code before posting this.
Note: Additionally I have MANUALLY checked the users by going to twitter and looking up their username, and they DO come up. For example, this is one of the users, and they do come up: https://twitter.com/rendrarh I have done this with MANY of the users in the list.
Note: This works when just manually entering a user (using this Get tweets of a public twitter profile ) , but not when pulling it from the file
I am using Twitter4j to get tweets of users and getting the following error:
TwitterException{exceptionCode=[7defbde2-0dc3a547], statusCode=404, message=Sorry, that page does not exist., code=34, retryAfter=-1, rateLimitStatus=RateLimitStatusJSONImpl{remaining=899, limit=900, resetTimeInSeconds=1510626518, secondsUntilReset=899}, version=4.0.4}
at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:164)
at twitter4j.HttpClientBase.request(HttpClientBase.java:57)
at twitter4j.HttpClientBase.get(HttpClientBase.java:75)
at twitter4j.TwitterImpl.get(TwitterImpl.java:1786)
at twitter4j.TwitterImpl.getUserTimeline(TwitterImpl.java:131)
at twitter4j.TwitterImpl.getUserTimeline(TwitterImpl.java:152)
at UserTweets.main(UserTweets.java:42)
Line 42 is : statuses.addAll(twitter.getUserTimeline(user));
Here is my code:
import java.io.File;
import java.util.*;
import twitter4j.*;
import twitter4j.conf.*;
public class UserTweets {
public static void main(String[] a) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("key")
.setOAuthConsumerSecret("key")
.setOAuthAccessToken("key")
.setOAuthAccessTokenSecret("key");
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
String user;
List statuses = new ArrayList();
int userCount = 1;
String fileName = "C:-----/spam-twitter-accounts.txt";
File file = new File(fileName);
Scanner input = new Scanner(file);
List<String> list = new ArrayList<String>();
while (userCount < 20 && input.hasNextLine()) {
try {
user = list.add(input.nextLine());
statuses.addAll(twitter.getUserTimeline(user));
System.out.println(statuses.toString());
if (statuses.size() == 20)
break;
}
catch(TwitterException e) {
e.printStackTrace();
}
}
}
}