Search code examples
javaweb-scrapingweb-crawlertwitter4j

Cannot crawl those tweets which contains hashag


I use twitter4j to crawl twitter but I am facing a very funny error:

when I try to crawl twitter4j for all tweets wiich contains hashtag(so my serach term would be just #), everything returns with and without hashtag but I just want to get those tweets that contain hashtag, here is my code:

        **String query = "#";
        System.out.println("[Current query is \"" + query + "\"]");
        // Query settings
        twitterQuery = new Query(query);
        // Result per page
        twitterQuery.setCount(resultPerPage);
        // Language code
        twitterQuery.setLang(lang);
    QueryResult result = twitter.search(twitterQuery);
    List<Status> tweets = result.getTweets();**

Can anyone help?


Solution

  • I would imagine that the Twitter4J library uses the Twitter API. Looking at the Twitter Search API docs it says to try constructing a query in the Twitter Advanced Search web page first.

    I was neither able to search for tweets containing a hash sign, nor to search for tweets containing a wildcard hashtag.

    This does not seem to be well documented anywhere, but after playing around with it for a while, it looks like you might be able to use filter:hashtags in the query.