how to pull info from json twitter quiry
in
Contributed Library Questions
•
2 years ago
i am using the twitter4j library and the quiry
http://stream.twitter.com/1/statuses/filter.json?locations=-150,-60,150,60
when i do this in the browser i get lots of interesting info like the logitue and latitude and the tweet text, but as soon as i put it into my sketch i can only seem to get the tweet text and for my experiment i need the longitude and latitude so i can map it.
Also it is running very slow (i get about 3 tweets ever 3 mins) i have tryed the code in another/simpler sketch to see if it was the quiry that was being slow or my sketch and it turns out its my sketch so if anyone has any ideas on how i can speed it up by editing my code that would be great.
Thanks
here is my code:
import com.twitter.processing.*;
//
// Library by twitter4j
//
//
//
//
//
//
//
//float for random position on my text
float xPos;
float yPos;
//float for my random color on text
float r, g, b;
//float for random text size
float textsize;
// this stores how many tweets we've gotten
int tweets = 0;
// and this stores the text of the last tweet
String tweetText = "";
void setup() {
size(1000,800);
// set up twitter stream object
TweetStream s = new TweetStream(this,
"stream.twitter.com", 80, "1/statuses/filter.json?locations=-150,-60,150,60", "TWITTERUSSER", "TWITTERPASWORD");
s.go();
background(0);
}
void draw() {
//random x/y position
xPos =(100);
yPos = (500);
background(0);
//random text size not yet working
textsize =(15);
// set up fonts
PFont font;
font = createFont("ArialMT-48.vlw", textsize);
textFont(font);
textSize(textsize);
fill(255);
// and draw the text of the last tweet
text(tweetText, xPos, yPos);
}
// called by twitter stream whenever a new tweet comes in
void tweet(Status tweet) {
// print a message to the console just for giggles if you like
// println("got tweet " + tweet.id());
// store the latest tweet text
tweetText = tweet.text();
// bump our tweet count by one
tweets += 1;
}
when i do this in the browser i get lots of interesting info like the logitue and latitude and the tweet text, but as soon as i put it into my sketch i can only seem to get the tweet text and for my experiment i need the longitude and latitude so i can map it.
Also it is running very slow (i get about 3 tweets ever 3 mins) i have tryed the code in another/simpler sketch to see if it was the quiry that was being slow or my sketch and it turns out its my sketch so if anyone has any ideas on how i can speed it up by editing my code that would be great.
Thanks
here is my code:
import com.twitter.processing.*;
//
// Library by twitter4j
//
//
//
//
//
//
//
//float for random position on my text
float xPos;
float yPos;
//float for my random color on text
float r, g, b;
//float for random text size
float textsize;
// this stores how many tweets we've gotten
int tweets = 0;
// and this stores the text of the last tweet
String tweetText = "";
void setup() {
size(1000,800);
// set up twitter stream object
TweetStream s = new TweetStream(this,
"stream.twitter.com", 80, "1/statuses/filter.json?locations=-150,-60,150,60", "TWITTERUSSER", "TWITTERPASWORD");
s.go();
background(0);
}
void draw() {
//random x/y position
xPos =(100);
yPos = (500);
background(0);
//random text size not yet working
textsize =(15);
// set up fonts
PFont font;
font = createFont("ArialMT-48.vlw", textsize);
textFont(font);
textSize(textsize);
fill(255);
// and draw the text of the last tweet
text(tweetText, xPos, yPos);
}
// called by twitter stream whenever a new tweet comes in
void tweet(Status tweet) {
// print a message to the console just for giggles if you like
// println("got tweet " + tweet.id());
// store the latest tweet text
tweetText = tweet.text();
// bump our tweet count by one
tweets += 1;
}
1