Step 6Send a Twitter update
Here's the minimum code to post a status update from Processing. You'll have to add the twitter4j jar file that you downloaded earlier to your Processing sketch though the Sketch->Add File menu.
// Send a status update to Twitter via the twitter4j API// You have to add the twitter4j-x.x.x.jar file to your sketch via Sketch->Add FileString twitterID = "XXX"; //your twitter IDString twitterPassword = "XXX"; //your twitter passwordvoid setup(){}void draw(){ //send new tweet on mouse click if(mousePressed) { sendTweet("Updating my status from Processing."); }}// Send the tweet passed in as String argumentvoid sendTweet(String msg) { //construct a new twitter object Twitter twitter = new Twitter(twitterID,twitterPassword); try { Status status = twitter.update(msg); System.out.println("Updated the status to [" + status.getText() + "]."); } catch (Exception e) { e.printStackTrace(); }}To make the updates more interesting, you'll probably want a whole set of alternative status messages that you can switch between. Take into account whether your cat is on or off the bed. How long she's been there. What time of day it is. Etc...
| « Previous Step | Download PDFView All Steps | Next Step » |
1
comment
|
Add Comment
|
![]() |
Add Comment
|












































