We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey everyone, I'm fairly new to processing, but I'm having a lot of fun and I try to learn as fast as I can. Im copying code here and there, and i customize it to my needs, understanding more and more of it. I managed to import the twitter4j library and I have no problems searching for tweets, but I'm really confused by trends. I'm not yet smart enough to fully understand the JavaDoc, but I found the getTrends() function a few days ago, but I have absolutely no clue how to call for it. I tried everything I could, but I couldnt get it to work.
Basically, I wanna make a trendsQuery just like my twitterQuery that offers trends as a result, not tweets.
I hope someone can help me out, i would really appreciate it.
simplified version of code so far:
import java.util.*;
import twitter4j.*;
Twitter twitter;
String [] receivedTweets = new String[100];
int x = 1;
void setup() {
// TWITTER AUTH ---TWITTER AUTH ---TWITTER AUTH ---TWITTER AUTH ---TWITTER AUTH ---TWITTER AUTH ---TWITTER AUTH ---TWITTER AUTH ---TWITTER AUTH ---TWITTER AUTH ---TWITTER AUTH ---
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("---");
cb.setOAuthConsumerSecret("---");
cb.setOAuthAccessToken("---");
cb.setOAuthAccessTokenSecret("---");
TwitterFactory tf = new TwitterFactory(cb.build());
twitter = tf.getInstance();
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
background(0);
fullScreen(P3D, 1);
twitterQuery("#design");
}
void draw() {
frameRate(24);
fill(0, 10);
rect(0, 0, 1920, 1080);
noCursor();
}
void twitterQuery(String searchString) {
Query query = new Query(searchString);
query.count(100);
println("Query made.");
//Try making the query request.
try {
QueryResult result = twitter.search(query);
ArrayList<Status> tweets = (ArrayList<Status>) result.getTweets();
for (int i = 0; i < tweets.size(); i++) {
Status t = tweets.get(i);
User u = (User) t.getUser();
String user = u.getName();
String msg = t.getText();
Date d = t.getCreatedAt();
receivedTweets[i] = msg;
println("Put " + receivedTweets[i] + " in Array at pos " + i);
}
}
catch (TwitterException te) {
println("Couldn't connect: " + te);
};
}
void mousePressed() {
fill(255);
println(receivedTweets[x]);
text(receivedTweets[x], 100, 100);
x++;
}