title: Twitter4j : Search for public tweets
body: <p>How does one search within public tweets using the Twitter4j library ? </p>
  
  <pre><code>public static void main(String[] args) {
          Twitter twitter = new TwitterFactory().getInstance();
          try {
              Query query = new Query("Cocaine");
              QueryResult result;
              do {
                  result = twitter.search(query);
                  List&lt;Status&gt; tweets = result.getTweets();
                  for (Status tweet : tweets) {
                      System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());
                  }
              } while ((query = result.nextQuery()) != null);
              System.exit(0);
          } catch (TwitterException te) {
              te.printStackTrace();
              System.out.println("Failed to search tweets: " + te.getMessage());
              System.exit(-1);
          }
      }
  </code></pre>
  
  <p>This gives me a <code>Authentication credentials are missing.</code> error</p>