Skip to content

Instantly share code, notes, and snippets.

@myy
Created November 2, 2013 05:24
Show Gist options
  • Save myy/7275859 to your computer and use it in GitHub Desktop.
Save myy/7275859 to your computer and use it in GitHub Desktop.
twitter4jを使ってprocessingでひたすらツイートを表示させるだけ.Handyというライブラリも使ってます(http://gicentre.org/handy/).
import twitter4j.conf.*;
import twitter4j.internal.async.*;
import twitter4j.internal.org.json.*;
import twitter4j.internal.logging.*;
import twitter4j.http.*;
import twitter4j.internal.util.*;
import twitter4j.api.*;
import twitter4j.util.*;
import twitter4j.internal.http.*;
import twitter4j.*;
import org.gicentre.handy.*;
static String consumer_key = "your consumer key";
static String consumer_secret = "your consumer secret";
static String oauth_token = "your OAuth token";
static String oauth_token_secret = "your OAuth token secret";
String keywords[] = {"query"};
TwitterStream twStream;
HandyRenderer h;
PImage icon = null;
String tweet = "";
boolean flag = false;
void setup() {
size(displayWidth, displayHeight);
frameRate(15);
background(0);
PFont myFont = createFont("Meiryo", 20);
textFont(myFont);
icon = loadImage("default.png"); // default
smooth();
h = new HandyRenderer(this);
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true);
cb.setOAuthConsumerKey(consumer_key);
cb.setOAuthConsumerSecret(consumer_secret);
cb.setOAuthAccessToken(oauth_token);
cb.setOAuthAccessTokenSecret(oauth_token_secret);
twStream = new TwitterStreamFactory(cb.build()).getInstance();
twStream.addListener(listener);
FilterQuery filterQuery = new FilterQuery();
filterQuery.track(keywords);
twStream.filter(filterQuery);
}
void draw() {
fadeToBlack();
if(flag) {
h.setRoughness(5);
int dx = int(random(width / 2));
int dy = int(random(height / 2));
strokeWeight(5);
fill(230);
stroke(0,255,255);
h.rect(dx, dy, 700, 250);
image(icon, dx+30, dy+30, 100, 100);
fill(0,0,0);
text(tweet, dx+140, dy+60, 500, 500);
flag = false;
}
}
// This listens for new tweet
StatusListener listener = new StatusListener() {
public void onStatus(Status status) {
if(!status.isRetweet()) {
flag = true;
println("@" + status.getUser().getScreenName() + " - " + status.getText());
icon = loadImage(status.getUser().getProfileImageURL(), "png");
tweet = status.getText();
}
}
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
// System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
}
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
// System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
}
public void onScrubGeo(long userId, long upToStatusId) {
// System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
}
public void onStallWarning(StallWarning warning) {
// System.out.println("Got stall warning: " + warning);
}
public void onException(Exception ex) {
ex.printStackTrace();
}
};
void fadeToBlack(){
noStroke();
fill(0,10);
rectMode(CORNER);
rect(0,0,width,height);
}
@myy
Copy link
Author

myy commented Jan 15, 2014

要確認
REST API SSL certificate updates | Twitter Developers https://dev.twitter.com/blog/rest-api-ssl-certificate-updates

@myy
Copy link
Author

myy commented Jan 15, 2014

Twitter / t4j_news: サービス・アプリが不調な場合は最新の #Twitter4J ... https://twitter.com/t4j_news/status/423256442225704960

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment