We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everybody,
I'm trying to write a sketch using Twitter API. I want to retrive tweets with a specific hashtag so I can use them. Unfortunately, I keep getting stuff like http related words in the middle of it.
Is there a practical way to prevent this or to remove them from the array?
This is the code I am using. These are all functions that are being called somewhere else.
Thank you so much
Best
void makeobject(){
//Make the twitter object and prepare the query
twitterInstance = new TwitterFactory(cb.build()).getInstance();
queryForTwitter = new Query("#summerparty");
queryForTwitter.count(50);
}
void createtquery() {
//Try making the query request.
try {
QueryResult result = twitterInstance.search(queryForTwitter);
tweets = (ArrayList) result.getTweets();
} //END of try()
catch (TwitterException te) {
println("Couldn't connect: " + te);
} //END Twitter Exception
} //END of void
void twitterdraw() {
for (int i = 0; i < tweets.size (); i++) {
Status t = (Status) tweets.get(i);
String user = t.getUser().getName();
String msg = t.getText();
// Date d = t.getCreatedAt();
println(msg);
//text(msg, 150, 150);
//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]);
} //END of for()
} //END of for()
//Draw a word from the list
int i = (int(random(0, words.size())) % words.size());
String word = words.get(i);
//Put it on the stage
text(word, 350, 110);
}
Answers
Http related words being...?
Hi,
literally URL's like these:
RT @garavoguebar: #HelloSummer with the ultimate #SummerParty this Friday #BBQ #Livemusic with Dean Mahon Music, JJ and... https://t.co/3QS…
When I wasn't sick yet. Hahaha. #Bright #Bright2016 #caesars #summerparty #party #partytime #clubbing #clubbin #clu… https://t.co/oEoT4GlNFC
thanks
Those are pictures attached to the tweets.
Split the string into words, use java's startsWith() method to weed out the words beginning with https://
something like:
Thank you so much. It works perfectly! The thing was bothering me a long time now and it's finally solved! :)