Twitter 4j and general geolocation of user in an area
              in 
             Contributed Library Questions 
              •  
              2 years ago    
            
 
           
             Here is a sketch I have been using to do a geoLocation search using the twitter4j library. I'm tring to get all the possible tweets from a location focusing only on the coordinates of the tweet. My goal is to get the exact position of the people during the day using twitter.
            
            
I created a loop to make the query every 10,4 sec (in order not to reach the twitter-rate limit) but there's something wrong.
I've done some tests tweeting from within the query coordinates but I can't get these tweets back in the output code.
            
Can anyone point me in the direction as to why?
            
Any advice or help would be appreciated
            
            
            
 
           
 
            
           I created a loop to make the query every 10,4 sec (in order not to reach the twitter-rate limit) but there's something wrong.
I've done some tests tweeting from within the query coordinates but I can't get these tweets back in the output code.
Can anyone point me in the direction as to why?
Any advice or help would be appreciated
- String ConsumerKey = "*******";
- String ConsumerSecret = "*******";
- String oauth_token = "*******";
- String oauth_token_secret = "*******";
- TwitterFactory tf;
- String geoURL;
- double lat;
- double lon;
- double res;
- String resUnit;
- import java.util.List;
- void setup() {
-   println("starting...");
-   // println("geoURL " + geoURL = "http://search.twitter.com/search.json?geocode=");
-   println();
-   
-   ConfigurationBuilder cb = new ConfigurationBuilder(); 
-   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("entering void draw class..."+ "\n"+ "\n");
-   println();
-   Twitter twitter = tf.getInstance();
-   // These values are from Milan (GoogleMaps)
 lat = 45.49985;
-   lon = 9.191093;
-   res = 25;
-   resUnit="km";
- int count = 0;
-   try {
-     while (count!=3) {
-           
- System.out.println(new Date());
-   try {
-     Query query = new Query().geoCode(new GeoLocation(lat,lon), res, resUnit);
-     query.rpp(100);
-     QueryResult result = twitter.search(query);
-     
-     //println(result);
-    
-     println("RPP: " + result.getResultsPerPage() + "\n");
-     List <Tweet> tweets = result.getTweets();
-     //println("tweets; " + tweets);
-     int myRpp = query.getRpp(); 
-     
-             for (int i=0; i < tweets.size(); i++) {
-               Tweet tweet = (Tweet)tweets.get(i);              
-               
-               if (tweet.getGeoLocation()!= null){
-                 GeoLocation loc=tweet.getGeoLocation();
-                 double myLon = loc.getLongitude();
-                 double myLat = loc.getLatitude();
-           
-                 println("@" + tweet.getFromUser() + ": longitude: "+ myLon + " latitude: "+myLat );     
-                 println ("result n° " + i);
-               }
-             }
-     println("Total fetched: "+ tweets.size());
-     println("--");
-     println(count);
-     println();
-     println();
-         //exit();
-     count +=1;
-     Thread.sleep(10400);
-     } catch (TwitterException te) {
-         te.printStackTrace();
-         println("Failed to search tweets: " + te.getMessage());
-         exit();
-       }
-       
-       }
- } catch (InterruptedException e) {
-         e.printStackTrace(); }  
- }
 
              
              1  
            
 
            
 
 
           
 
             
 
             
 
             
 
            