Twitter 4j query
in
Contributed Library Questions
•
2 years ago
Hi everyone , im trying to get my search twitter sketch to repeat it call , call Twitters Api every x amount of seconds.
at the moment its set to rrp(100) which can be changed but i would like to show the amount a certain word is being used. and therefore need to search frequently.
ive seen there is a rule for setSince (date) but i need the sketch to refresh its query. any help for my final project would be fantastic.
my code is from Blprnt tutorial here -
http://blog.blprnt.com/blog/blprnt/quick-tutorial-twitter-processing#idc-cover
- Twitter myTwitter;
- void setup() {
- myTwitter = new Twitter("username", "password");
- try {
- Query query1 = new Query("sad");
- Query query2 = new Query("happy");
- query1.setRpp(5000);
- query2.setRpp(5000);
- query1.setSince(20110414);
- query2.setSince(20110414);// sets date on query
- QueryResult result1 = myTwitter.search(query1);
- QueryResult result2 = myTwitter.search(query2);
- ArrayList tweets1 = (ArrayList) result1.getTweets();
- for (int i = 0; i < tweets1.size(); i++) {
- Tweet t = (Tweet) tweets1.get(i);
- String user = t.getFromUser();
- String msg = t.getText();
- Date d = t.getCreatedAt();
- println("Tweet by " + user + " at " + d + ": " + msg);
- };
- ArrayList tweets2 = (ArrayList) result2.getTweets();
- for (int i = 0; i < tweets2.size(); i++) {
- Tweet t = (Tweet) tweets2.get(i);
- String user = t.getFromUser();
- String msg = t.getText();
- Date d = t.getCreatedAt();
- println("Tweet by " + user + " at " + d + ": " + msg);
- };
- }
- catch (TwitterException te) {
- println("Couldn't connect: " + te);
- };
- };
- void draw() {
- };
1