GeoLocation Twitter Search: Twitter4j
in
Contributed Library Questions
•
2 years ago
Hi,
Here is a sketch I have been using to do a geoLocation search using the twitter4j library. It executes and prints the search URL but then doesn't print the tweets or count the tweets.size. When you enter the URL into the browser there are results there but for some reason it doesn't display them.
The for() loop isn't running for some reason. Can anyone point me in the direction as to why?
Any advice or help would be appreciated
Here is a sketch I have been using to do a geoLocation search using the twitter4j library. It executes and prints the search URL but then doesn't print the tweets or count the tweets.size. When you enter the URL into the browser there are results there but for some reason it doesn't display them.
The for() loop isn't running for some reason. Can anyone point me in the direction as to why?
Any advice or help would be appreciated
- import twitter4j.conf.*;
import twitter4j.internal.async.*;
import twitter4j.internal.org.json.*;
import twitter4j.internal.logging.*;
import twitter4j.json.*;
import twitter4j.internal.util.*;
import twitter4j.management.*;
import twitter4j.auth.*;
import twitter4j.api.*;
import twitter4j.util.*;
import twitter4j.internal.http.*;
import twitter4j.*;
import twitter4j.internal.json.*;
import twitter4j.media.*;
//package twitter4j.examples.search;
String ConsumerKey = "**********************************";
String ConsumerSecret = "***************************************************";
String oauth_token = "********************************************************************";
String oauth_token_secret = "***************************************************";
TwitterFactory tf;
String geoURL;
String lat;
String lon;
String res;
import java.util.List;
void setup() {
println("setup");
println();
geoURL = "http://search.twitter.com/search.json?geocode=";
println("geoURL" + geoURL);
println();
ConfigurationBuilder cb = new ConfigurationBuilder(); //ConfigurationBuilder declared cb is a new instance of this
cb.setDebugEnabled(true)
.setOAuthConsumerKey(ConsumerKey) //sets the Consumer Key String
.setOAuthConsumerSecret(ConsumerSecret) //sets the Consumer Secret String
.setOAuthAccessToken(oauth_token)
.setOAuthAccessTokenSecret(oauth_token_secret);
tf = new TwitterFactory(cb.build());
}
void draw() {
println("void draw");
println();
Twitter twitter = tf.getInstance();
// These values can later be passed over from android
lat = "52.9510";
lon = "-1.1355";
res = "1mi";
try {
QueryResult result = twitter.search(new Query(geoURL + lat + "," + lon + "," + res));
println(result);
List <Tweet> tweets = result.getTweets();
println("tweets; " + tweets);
println("tweet count = " + tweets.size());
for (int i=0; i < tweets.size(); i++)
{
Tweet tweet = (Tweet)tweets.get(i);
println("@" + tweet.getFromUser() + " : " + tweet.getText());
println ("results;" + tweets.size());
}
exit();
}
catch (TwitterException te) {
te.printStackTrace();
println("Failed to search tweets: " + te.getMessage());
exit();
}
}
2