thelockwood | Dan Lockwood | Web & Graphic Designer | Digital Art & Technology Student.
26May/110

Basic Querying

As I had never used the Twitter4J library before I searched for an online tutorial to help. As I was impressed with the ‘Just Landed’ visualisation, I used a tutorial created by the same developer Jer Thorp. On his site I found a piece of code that simply searched for a key word and would display the last one hundred people that had tweeted it.

Twitter myTwitter;

 

void setup() {

myTwitter = new Twitter("yourTwitterUserName", "yourTwitterPassword");

try {

 

Query query = new Query("sandwich");

query.setRpp(100);

QueryResult result = myTwitter.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);

};

 

}

catch (TwitterException te) {

println("Couldn't connect: " + te);

};

};

 

void draw() {

 

};

 

This then printed on the console the last hundred people that tweeted the word ‘sandwich’. To make my Artefact work I needed to adapt this to search for two parameters at once, i.e. both a location on the globe and a key word.

 

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.