Reputation: 792
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!
Upvotes: 0
Views: 1089
Reputation: 4347
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)
Upvotes: 1