List of usage examples for twitter4j TwitterFactory TwitterFactory
public TwitterFactory(String configTreePath)
From source file:org.mixare.utils.TwitterClient.java
License:Open Source License
/** * Query the twitter search API using oAuth 2.0 * @return// ww w.j a v a 2s . co m */ public static String queryData() { ConfigurationBuilder cb = new ConfigurationBuilder(); //to be configured in a properties... cb.setDebugEnabled(true).setOAuthConsumerKey("mt10dv6tTKacqlm14lw5w") .setOAuthConsumerSecret("4kRV1E1XIU3kj4JQj2R5LE1yct0RRaRl9sB5PpPrB0") .setOAuthAccessToken("390019380-IQ5VdvUKvxY9JOsTToEU8ElCabebc76H9X2g3QX4") .setOAuthAccessTokenSecret("ghJn4LTfDr7uHUCsbt6ycmpeVTwwpa3hZnXyEjyZvs"); cb.setJSONStoreEnabled(true); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); Query query = new Query(); query = query.geoCode(new GeoLocation(lat, lon), rad, Query.KILOMETERS); String jsonArrayAsString = "{\"results\":[";//start try { QueryResult result = twitter.search(query); int size = 0; for (Status status : result.getTweets()) { { if (status.getGeoLocation() != null) { String jsonSingleObject = DataObjectFactory.getRawJSON(status); if (size == 0) jsonArrayAsString += jsonSingleObject; else jsonArrayAsString += "," + jsonSingleObject; size++; } } } jsonArrayAsString += "]}";//close array return jsonArrayAsString; } catch (Exception e) { Log.e(Config.TAG, "Error querying twitter data :" + e); e.printStackTrace(); } return null; }