Created
March 9, 2013 22:25
-
-
Save loadedsith/5126036 to your computer and use it in GitHub Desktop.
Processing Twitter Stream Tracker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.core.*; | |
import twitter4j.*; | |
import twitter4j.conf.ConfigurationBuilder; | |
private static final long serialVersionUID = 1L; | |
private static TwitterStream tw; | |
public static void setupTwitter() throws TwitterException{ | |
ConfigurationBuilder cb = new ConfigurationBuilder(); | |
cb.setOAuthConsumerKey("xxx"); | |
cb.setOAuthConsumerSecret("xxx"); | |
cb.setOAuthAccessToken("xxx-xxx"); | |
cb.setOAuthAccessTokenSecret("xxx"); | |
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); | |
StatusListener listener = new StatusListener() { | |
@Override | |
public void onStatus(Status status) { | |
System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); | |
System.out.println(status.getCreatedAt()); | |
} | |
@Override | |
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { | |
System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); | |
} | |
@Override | |
public void onTrackLimitationNotice(int numberOfLimitedStatuses) { | |
System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); | |
} | |
@Override | |
public void onScrubGeo(long userId, long upToStatusId) { | |
System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); | |
} | |
@Override | |
public void onException(Exception ex) { | |
ex.printStackTrace(); | |
} | |
@Override | |
public void onStallWarning(StallWarning arg0) { | |
System.out.println("Got stall warning"); | |
} | |
}; | |
FilterQuery fq = new FilterQuery(); | |
String keywords[] = {"@Magnetic_Tweets", "@Magnetic_Tweets","#Magnetic_Tweets", | |
"#Magnetic_Tweets","@Loadedsith",}; | |
fq.track(keywords); | |
twitterStream.addListener(listener); | |
twitterStream.filter(fq); | |
} | |
@Override | |
public void setup() { | |
size(200,200); | |
background(0); | |
try { | |
setupTwitter(); | |
} catch (TwitterException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
@Override | |
public void draw() { | |
stroke(255); | |
if (mousePressed) { | |
line(mouseX,mouseY,pmouseX,pmouseY); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment