0

I am trying to use the Twitter REST API to get the trending topics from Twitter. I tried Simplest Java example retrieving user_timeline with twitter API version 1.1 but I couldn't make it to work because the HttpClient class is abstract in the newer versions of apache.

So, basically, I have no idea how to use the API based on the documentation on dev.twitter. The only thing I have achieved is to post a tweet using twitter4j, but it has no way to get Trending topics by itself.

I've also seen a lot of tutorials and how-to's but they seem to be outdated and nothing works!

Community
  • 1
  • 1

1 Answers1

1

Check Apache HttpClient 4.5 tutorial here

Simple Get request looks like ;

CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet("http://targethost/homepage");
CloseableHttpResponse response1 = httpclient.execute(httpGet);

Implement twitter api on top of it.

Edit:

HttpClient has this execute function;

@Override
public CloseableHttpResponse execute(
        final HttpUriRequest request) throws IOException, ClientProtocolException {
    return execute(request, (HttpContext) null);
}

which takes HttpUriRequest interface (implemented by abstract HttpRequestBase and also by HttpGet)

Fatih Donmez
  • 4,319
  • 3
  • 33
  • 45
  • The execute method cannot have an HttpGet object as a parameter, could you explain how I should use it? – Savvas Parastatidis Nov 04 '15 at 17:55
  • Well, I had downloaded version 4.5.1 and it's the latest on apache site.The execute function is in the CloseableHttpClient class as you said. The HttpGet class extends HttpRequestBase, which implements HttpUriRequest as you said. But netbeans does not let me call execute saying no suitable method for execute(HttpGet) – Savvas Parastatidis Nov 04 '15 at 22:47
  • I tried with 4.5 but I think it's probably same with 4.5.1. I'm not an expert with netbeans but I think it cached old version in somewhere so you get this error. Make sure you deleted the old one as a dependency. – Fatih Donmez Nov 05 '15 at 06:04