Unable to fetch some tweets


#1

We are using twitter4j latest version 4.0.x. We are unable to fetch tweets from my twitter account using search by keyword (Any of the keywords option).


#2

Any example code? what error are you seeing? what are you searching for?

I assume since you posted this in the Streaming category you are using a filter by keyword on the public streaming endpoint?


#3

We are using twitter4j 4.0.x and the code as follows

    private TwitterClient(String consumerKey, String consumerSecret,
            String accessToken, String accessTokenSecret) {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(false).setOAuthConsumerKey(consumerKey)
                .setOAuthConsumerSecret(consumerSecret)
                .setOAuthAccessToken(accessToken)
                .setOAuthAccessTokenSecret(accessTokenSecret);
        TwitterFactory tf = new TwitterFactory(cb.build());
        twitter = tf.getInstance();
        unauthenticatedTwitter = new TwitterFactory().getInstance();
    }

    public static TwitterClient getInstance(String consumerKey,
            String consumerSecret, String accessToken, String accessTokenSecret) {
        String key = consumerKey;
        if (twitterClients.get(key) == null) {
            twitterClients.put(key, new TwitterClient(consumerKey,
                    consumerSecret, accessToken, accessTokenSecret));
        }
        log.trace("Cache size = {}", twitterClients.size());

        return twitterClients.get(key);
    }


public List<Status> searchTweets(String keyword) {
        String[] keywords = keyword.split(" ");
        String keywordWithOr = StringUtils.join(keywords, " OR ");
        Query searchQuery = new Query(keywordWithOr);

        return this.searchTweets(searchQuery);
    }

public synchronized List<Status> searchTweets(Query query) {
        List<Status> tweets = new ArrayList<Status>(64);
        query.setCount(100);
        query.setLang("en");
        QueryResult result = null;

        try {
            result = twitter.search(query);
            List<Status> results = (ArrayList<Status>) result.getTweets();
            TwitterClient.printStatuses(results);
            tweets.addAll(results);
        } catch (TwitterException e) {
            log.trace("Failed to search tweets: {}", e);
        }

        return tweets;
    }