Anyone know if it's possible to get ONLY the tweet that contain entities (Hashtag and Photos) with twitter4j ?
Here is my code, it works fine but I get all the tweet including the ones that don't have entities.
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(TwitterConstantes.APIKEY)
.setOAuthConsumerSecret(TwitterConstantes.APIKEYSECRET)
.setOAuthAccessToken(TwitterConstantes.TOKEN)
.setOAuthAccessTokenSecret(TwitterConstantes.TOKENSECRET);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
double res = 5;
//Query query = new Query(this.text);
Query query = new Query().geoCode(new GeoLocation(latitude,longitude), res, Query.KILOMETERS.toString());
query.setResultType(Query.RECENT); // get the recent tweets
query.count(100);
QueryResult result = twitter.search(query);
do {
for (Status tweet : result.getTweets()) {
//if (tweet.isRetweet()){continue;}
try {
Status tweetById = twitter.showStatus(tweet.getId());
String url= "https://twitter.com/" + tweetById.getUser().getScreenName()
+ "/status/" + tweetById.getId();
List<String> hashtags = new ArrayList<String>();
HashtagEntity[] hashtagsEntities = tweetById.getHashtagEntities();
for (HashtagEntity hashtag : hashtagsEntities){
System.out.println(hashtag.getText());
}
ExtendedMediaEntity[] medias = tweetById.getExtendedMediaEntities();
for (ExtendedMediaEntity m : medias){
System.out.println(m.getMediaURL());
}
} catch (TwitterException e) {
System.err.print("Failed to search tweets: " + e.getMessage());
return;
}
}
query = result.nextQuery();
if(query!=null){
result = twitter.search(query);
}
}while(query!=null);