title: Spring RestTemplate gives 401 Authorization Required while getting data from Twitter
body: <p>I am trying to get twitter tweets using Spring RestTemplate. My code is below:</p>
  
  <pre><code>    public static void main(String[] args) {
  
      RestTemplate restTemplate = new RestTemplate();
  
      org.springframework.http.HttpHeaders httpHeaders = new org.springframework.http.HttpHeaders();
  
      String url = "https://api.twitter.com/1.1/search/tweets.json q=java";        
      String headerName = "Authorization";
      String headerValue = OAUTH_PARAMETERS
      httpHeaders.add(headerName, headerValue);
      httpHeaders.add("Content-Type", "application/json");
      HttpEntity&lt;String&gt; requestEntity = new HttpEntity&lt;&gt;("Headers", httpHeaders);
      System.out.println("&gt;&gt;&gt;&gt;&gt;&gt;&gt;" + restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class).getBody());
  }
  </code></pre>
  
  <p>I am getting following errors:</p>
  
  <blockquote>
    <p>Exception in thread "main"
    org.springframework.web.client.HttpClientErrorException: 401
    Authorization Required    at
    org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:91)
      at
    org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:641)
      at
    org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:597)
      at
    org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557)
      at
    org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:475)
      at
    com.lftechnology.amlf.screening.service.impl.BalanceMediaSearchResultServiceImpl.main(BalanceMediaSearchResultServiceImpl.java:202)</p>
  </blockquote>