Unexpected token: (
in
Contributed Library Questions
•
10 months ago
Hey guys
I am sort of a newbie with Processing but looking to do some cool things with it for my newsroom. I'm trying to build a tweet stream animation based on hashtags for teams. I got the code from this blog: blog.blprnt.com/blog/blprnt/updated-quick-tutorial-processing-twitter
Below is my code, with the code keys blocked out, and I keep getting "unexpected token: (" error at the cb.setOAuthConsumerKey line (line 12).
Can someone help?
//Build an ArrayList to hold all of the words that we get from the imported tweets
ArrayList<String> words = new ArrayList();
void setup() {
//Set the size of the stage and the backgroud to black.
size(550,550);
background(0);
smooth();
//Credentials
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("xxxxxxxxxxxxx");
cb.setOAuthConsumerSecret("xxxxxxxxxxxx");
cb.setOAuthAccessToken("xxxxxxxxx-xxxxxxxxxxx");
cb.setOAuthAccessTokenSecret("xxxxxxxxxxxxxxx");
//Make the Twitter object and prepare the query
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
Query query = new Query("#OrlandoPirates");
query.setRpp(100);
//Try making the query request.
try {
QueryResult result = twitter.search(query);
ArrayList tweets = (ArrayList) result.getTweets();
for (int i = 0; i < tweets.size(); i++) {
Tweet t = (Tweet) tweets.get(i);
String user = t.getFromUser();
String msg = t.getText();
Date d = t.getCreateAt();
println("Tweet by " + user + " at " + d + ": " + msg);
//Break the tweet into words
String[] input = msg.split(" ");
for (int j = 0; j < input.length; j++) {
//Put each word into the words ArrayList
words.add(input[j]);
}
};
}
catch (TwitterException te) {
println("Couldn't connect: " + te);
};
}
void draw() {
//Draw a faint black rectangle over what is currently on the stage so it fades over t
fill(0,1);
rect(0,0,width,height);
//Draw a word from the list of words that we've built
int i = (frameCount % words.size());
String word = words.get(i);
//Put it somewhere random on the stage, with a random size and colour
fill(255,random(50,150));
textSize(random(10,30));
text(word, random(width),random(height));
}
I am sort of a newbie with Processing but looking to do some cool things with it for my newsroom. I'm trying to build a tweet stream animation based on hashtags for teams. I got the code from this blog: blog.blprnt.com/blog/blprnt/updated-quick-tutorial-processing-twitter
Below is my code, with the code keys blocked out, and I keep getting "unexpected token: (" error at the cb.setOAuthConsumerKey line (line 12).
Can someone help?
//Build an ArrayList to hold all of the words that we get from the imported tweets
ArrayList<String> words = new ArrayList();
void setup() {
//Set the size of the stage and the backgroud to black.
size(550,550);
background(0);
smooth();
//Credentials
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("xxxxxxxxxxxxx");
cb.setOAuthConsumerSecret("xxxxxxxxxxxx");
cb.setOAuthAccessToken("xxxxxxxxx-xxxxxxxxxxx");
cb.setOAuthAccessTokenSecret("xxxxxxxxxxxxxxx");
//Make the Twitter object and prepare the query
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
Query query = new Query("#OrlandoPirates");
query.setRpp(100);
//Try making the query request.
try {
QueryResult result = twitter.search(query);
ArrayList tweets = (ArrayList) result.getTweets();
for (int i = 0; i < tweets.size(); i++) {
Tweet t = (Tweet) tweets.get(i);
String user = t.getFromUser();
String msg = t.getText();
Date d = t.getCreateAt();
println("Tweet by " + user + " at " + d + ": " + msg);
//Break the tweet into words
String[] input = msg.split(" ");
for (int j = 0; j < input.length; j++) {
//Put each word into the words ArrayList
words.add(input[j]);
}
};
}
catch (TwitterException te) {
println("Couldn't connect: " + te);
};
}
void draw() {
//Draw a faint black rectangle over what is currently on the stage so it fades over t
fill(0,1);
rect(0,0,width,height);
//Draw a word from the list of words that we've built
int i = (frameCount % words.size());
String word = words.get(i);
//Put it somewhere random on the stage, with a random size and colour
fill(255,random(50,150));
textSize(random(10,30));
text(word, random(width),random(height));
}
1