Processing -> Twitter Mentions
in
Contributed Library Questions
•
1 year ago
Hi Guys
I'm trying to get Processing to send a serial command when someone @'s my twitter account. I'm using twitter4J and this is what i've got so far:
- // This is where you enter your Oauth info
- static String OAuthConsumerKey = "KEY";
- static String OAuthConsumerSecret = "CONSUMERS";
- // This is where you enter your Access Token info
- static String AccessToken = "TOKEN";
- static String AccessTokenSecret = "TOKENSECRET";
- // Just some random variables kicking around
- String myTimeline;
- java.util.List statuses = null;
- Twitter twitter = new TwitterFactory().getInstance();
- RequestToken requestToken;
- String[] theSearchTweets = new String[11];
- int lastTime = 0;
- void setup() {
- size(100,100);
- background(0);
- connectTwitter();
- }
- void draw() {
- background(204);
- if( millis() - lastTime >= 30000){
- getTimeline();
- lastTime = millis();
- }
- }
- // Initial connection
- void connectTwitter() {
- twitter.setOAuthConsumer(OAuthConsumerKey, OAuthConsumerSecret);
- AccessToken accessToken = loadAccessToken();
- twitter.setOAuthAccessToken(accessToken);
- }
- // Loading up the access token
- private static AccessToken loadAccessToken(){
- return new AccessToken(AccessToken, AccessTokenSecret);
- }
- // Get mentions
- void getTimeline() {
- try {
- statuses = twitter.getMentions();
- } catch(TwitterException e) {
- println("Get timeline: " + e + " Status code: " + e.getStatusCode());
- }
- for(int i=0; i<statuses.size(); i++) {
- Status status = (Status)statuses.get(i);
- println(status.getUser().getName() + ": " + status.getText());
- }
- }
I would like the sketch to count how many NEW tweets have come through since the last time it checked. Any ideas?
1