We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Processing and Twitter
Pages: 1 2 3 4 ... 6
Processing and Twitter (Read 65230 times)
Re: Processing and Twitter
Reply #15 - Mar 22nd, 2009, 12:57am
 
Thanks, not really Java programmer, and the instructions arent that great on the lib website
Re: Processing and Twitter
Reply #16 - Mar 23rd, 2009, 9:29am
 
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();
Re: Processing and Twitter
Reply #17 - Apr 4th, 2009, 1:03pm
 
Thanks for the great information. I'm pretty sure I have the syntax correct, but I continue to get errors.
Code:

Twitter twitter = new Twitter("twitterid","twitterpswd");
Status status = twitter.update("Hello World");


I get the error "The type Status is ambiguous"

I've searched all over the Twitter4j site but I'm not used to java so I'm totally lost.

-Fork
Re: Processing and Twitter
Reply #18 - Apr 4th, 2009, 2:17pm
 
I got it all figured out. I copied and pasted into a new sketch and dropped in the .jar again, and the error went away. I started getting the TwitterException error so I wrapped it in a try/catch and it worked perfectly. Check out my project at www.laughingdrake.com, I call it the TweetEasy. You guys are awesome.

-Fork
Re: Processing and Twitter
Reply #19 - Apr 5th, 2009, 4:07pm
 
hey Fork... did you know that projekt ?
http://www.todayandtomorrow.net/2009/04/06/baker-tweet/

thats a good way to use it i guess
Re: Processing and Twitter
Reply #20 - Apr 7th, 2009, 1:25pm
 
hey guys, I'm pretty new to processing and need a little help using twitter4j..

I'm trying to retrieve my recent status messages but it wont work. Its gives me this error

"cannot convert from List<status> to String"

Code:
Twitter twitter;
String myTimeline;
User[] friends;
String username = "myusername"; // add your own here
String password = "mypass"; // add your own here
twitter = new Twitter(username,password);

myTimeline = twitter.getUserTimeline();

   println(myTimeline);
 }
}

Re: Processing and Twitter
Reply #21 - Apr 9th, 2009, 9:44am
 
Really need some help with this please guys... could someone point me in the right direction please?
Re: Processing and Twitter
Reply #22 - Apr 10th, 2009, 7:42am
 
an example on how to get the timeline from a user and print it to the console:

           List statuses = twitter.getUserTimeline();
           for( int i=0; i<statuses.size(); i++ )
           {
               Status status = (Status)statuses.get(i);
               println(status.getUser().getName() + ":" +
                                  status.getText());
           }
Re: Processing and Twitter
Reply #23 - Apr 10th, 2009, 8:42am
 
thank you Smiley
Re: Processing and Twitter
Reply #24 - Apr 11th, 2009, 1:27am
 
ok so it returns the error:

"The type List is ambiguous"

was I ment to assign it to a datatype and if so which one/how (im fairly new to processing)
Re: Processing and Twitter
Reply #25 - Apr 11th, 2009, 4:56am
 
you'll need to import java.util.List
Re: Processing and Twitter
Reply #26 - Apr 14th, 2009, 8:17am
 
I've looked for java.util.List, on the web and on my system but cant find it.. anyone know where it might be?
Re: Processing and Twitter
Reply #27 - Apr 14th, 2009, 8:41am
 
java.util.List is part of the standard Java system, you don't need to download anything.

The problem is that there's a List type in another library, and processing doesn't know which oe to use, so you have to explicitly say java.util.List foo=something not just List foo=something.
Re: Processing and Twitter
Reply #28 - Apr 14th, 2009, 10:12am
 
so is this right..

Code:
java.util.List statuses = twitter.getUserTimeline(); 



because I get an error which says

Unhandled exception type TwitterException
Re: Processing and Twitter
Reply #29 - Apr 14th, 2009, 10:15am
 
yes its right. you're error is about exceptions. use try/catch

try
{
 java.util.List statuses = twitter.getUserTimeline();
}
catch( TwitterException e)
{
 // catch error here
}

hopefully you will be on your way now
Pages: 1 2 3 4 ... 6