I need help making this code more efficient but still functions the same, such as by making it access the Twitter API fewer times. When I run this code for like 1 min, I get an error from Twitter saying that it exceeds limits.
List<Status> tweets = result.getTweets();
for (Status tweet : tweets) {
if(!(tweet.getUser().getScreenName().toString().equals("gh") || tweet.getUser().getScreenName().toString().equals("gh"))){
boolean found = false;
List<Status> Stats= tw.getHomeTimeline();
for (Status StatList : Stats) {
if(StatList.getTweetText().equals(tweet.getTweetText())){
found = true;
break;
try {
System.out.println(tweet.getUser().getScreenName() );
Thread.sleep(2000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}else{
// nothing here
}
}
if (found) // you can move this and the initialisation(boolean found = false) out side the upper if statement
System.out.println("false");
else
System.out.println("turn");
}else{
System.out.println("blocked");
}
}
result
is? \$\endgroup\$