Since I've had several requests for help through email since I've posted here last, I thought I'd post the bit of code I wrote a while ago. Its nothing special I'm afraid, I'm not a programmer by any stretch of the imagination. It is also the only thing I have done with Twitter4J so far.
This is a sketch that reads some data for each of your Twitter friends and outputs the whole thing as a tab-separated file. Back then I remember I had to restart this thing several times because I kept hitting the Twitter API rate limit. I am sure there are much better ways of doing this, but it worked for me.
In case you're wondering, I used the resulting TSV file for a simple visualization, which you can see here:
http://leapfrog.nl/blog/archives/2008/06/02/sketching-in-code-twitter-processing-dataviz/
Anyway, here is the code. Again, I'm posting this mainly in the hopes of helping others to get started with the Twitter4J library. Nothing more.
(Make sure the Twitter4J JAR is in the code folder inside your sketch library.)
Code:
// Use this to start at a friend of your choosing when you've hit the Twitter API rate limit.
int startingPoint = 0;
Twitter twitter;
int myFriendsCount;
User[] friends;
String username = ""; // add your own here
String password = ""; // add your own here
twitter = new Twitter(username,password);
PrintWriter tsv = createWriter("friends.tsv");
try {
myFriendsCount = twitter.getFriends().size();
friends = new User[myFriendsCount];
for (int i = startingPoint; i < myFriendsCount; i++) {
friends[i] = (User) twitter.getFriends().get(i);
int id = friends[i].getId();
String screenName = friends[i].getScreenName();
UserWithStatus extendedFriend = twitter.getUserDetail(str(id));
int friendsCount = extendedFriend.getFriendsCount();
int followersCount = extendedFriend.getFollowersCount();
int statusesCount = extendedFriend.getStatusesCount();
tsv.println(id + "\t" + screenName + "\t" + friendsCount + "\t" + followersCount + "\t" + statusesCount);
println(nf(i, 3) + " loaded friend " + screenName + " ("+ id +")");
}
} catch (TwitterException e) {
println(e.getStatusCode());
}
tsv.flush();
tsv.close();
println("Done.");
exit();