Twitter4j - 只包含实体的推文(标签和照片)

时间:2015-10-13 18:11:13

标签: java twitter twitter4j

任何人都知道是否可以通过twitter4j获取包含实体(标签和照片)的推文 ONLY

这是我的代码,它工作正常,但我收到所有推文,包括那些没有实体的推文。

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);

0 个答案:

没有答案