Reputation: 11
I am trying to find a way to search for tweets with a specific hashtag AND tweets that only have pictures/media.
Searching for a hashtag is working:
Step #1
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
Query query = new Query("#test");
query.setResultType(Query.RECENT);
query.setRpp(100);
QueryResult result = twitter.search(query);
.....
However, this returns all the most recent tweets up to 100 with the hashtag "test". Then I have to filter the ones with media
Step #2
Loop through the tweets and get the ones with media/pic
I want to skip step #2 and tell the query to retrieve only the ones with media. is that possible...I am particularly interested in the ones with pics.
Any help?
Upvotes: 1
Views: 1229
Reputation: 182
I know it's been a long time but this may help other people who want to learn the answer.
List<twitter4j.Status> tweets=result.getTweets();
for(twitter4j.Status tweet : tweets){
if(tweet.getMediaEntities().length!=0){//If there is media in a tweet
//Do anything you want with image
//tweet.getMediaEntities()[0].getMediaURL() is url of image in a tweet. For example:
publishProgress(tweet.getMediaEntities()[0].getMediaURL());
//Log.d(TAG, tweet.getMediaEntities()[0].getMediaURL()));
}
}
Upvotes: 1
Reputation: 151
I know this is kinda late, but try including "pic.twitter.com" in your search. That won't have all the pictures, but you can add other urls as well.
Upvotes: 0