0

I am trying to build a Jersey Rest Client to use the Twitter search api.

The code is as folows:

   package twitter.client.example;

   import com.sun.jersey.api.client.Client;
   import com.sun.jersey.api.client.ClientResponse;
   import com.sun.jersey.api.client.WebResource;
   import com.sun.jersey.api.client.config.ClientConfig;
   import com.sun.jersey.api.client.config.DefaultClientConfig;


   public class TwitterClient {
public static void main(String[] args) {
    try {

        ClientConfig config = new DefaultClientConfig();

        Client client = Client.create();

        WebResource webResource = client
           .resource("http://search.twitter.com/search.json?      lang=en&q=pizza");


        ClientResponse response = webResource.accept("application/json")
                   .get(ClientResponse.class);



        if (response.getStatus() != 200) {
           throw new RuntimeException("Failed : HTTP error code : "
            + response.getStatus());
        }

        String output = response.getEntity(String.class);

        System.out.println("Output from Server .... \n");
        System.out.println(output);

      } catch (Exception e) {

        e.printStackTrace();

      }

}

}

When I run this, I get a com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException:Connection timed out: connect exception

Is there something that I am missing out in the code or can it be due to proxy settings? Do I need to incorporate OAuth or is the search api still unauthenticated?

Thanks, Sakshi

VikramV
  • 1,061
  • 2
  • 11
  • 27

0 Answers0