We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys, i'm fairly new to processing
but i found this code from a guy that he made in 2011.
Putting in a hashtag and it becomes a visual.. now processing says the SetRpp function
doesnt exist..
Is it because this code is pretty old?
anyway it seems really short and efficient.
would appreciate some help!
(i have everything set up in the library twitter4j-core etc)
Thanks!
//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 background to black.
size(550,550);
background(0);
smooth();
//Credentials
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("INSERT");
cb.setOAuthConsumerSecret("INSERT");
cb.setOAuthAccessToken("INSERT");
cb.setOAuthAccessTokenSecret("INSERT");
//Make the twitter object and prepare the query
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
Query query = new Query("#OWS");
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.getCreatedAt();
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 time.
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));
}
Answers
you seem to be missing imports
setRpp is in twitter4j version 2.1.0
http://twitter4j.org/oldjavadocs/2.1.0/twitter4j/Query.html
but isn't in (what i think are) the current docs
http://twitter4j.org/javadoc/twitter4j/Query.html
try setCount() instead - the descriptions are similar (rpp = results per page)
Thanks so much for you reply dude! so i've changed it.. and i had been changing the setRpp but then it says: "Cannot find a class or type named "tweet"
i realized i forgot to import the files from the library aswel.. so i did that
what could it mean by tweet? i read somewhere that i had to change it to status, but that doesnt work!
this fills the list of results. maybe twitter.search() is returning different items now.
2011 is 5 years ago! a lot can change in 5 years (2 major api revisions of twitter4j for one thing)
In general, your error messages give you a line number. You need to look at the line number to see inspect the code that is wrong! Clicking on the error may take you to that line number.
For example (I don't know), if you wrote:
Then you are referring to an object class "tweet" but your library doesn't define any such thing. Processing is case-sensitive -- the library (and the examples you started with) define a class "Tweet", not "tweet." So, no class or type found until you use the correct class name as defined in the library you are using:
yes, the results are now of type Status
http://twitter4j.org/javadoc/twitter4j/QueryResult.html#getTweets--
and here's the definition of Status
http://twitter4j.org/javadoc/twitter4j/Status.html
which contains text.
and getFromUser() now seems to be getUser(),which returns a User. who has a name and a screenname...
Yep that's true! i changed a lot in the past time got this now.. it just says unexpected token.. am i close you think or should i just throw in the towel ;))
lines 1, 2, 3 look out of place
line 37 looks like it's missing something. ditto line 39
did you globally find / replace something you shouldn't've?