-
-
Save jderda/ec4ec4349e20ea8ad91e85398c3839dd to your computer and use it in GitHub Desktop.
Sample HttpClient code using OAuth token
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void readRemoteData() throws URISyntaxException { | |
String oauthToken = "ABCDEFGHIJK...."; | |
CloseableHttpClient httpclient = HttpClients.createDefault(); | |
URIBuilder requestUri = new URIBuilder("https://query.yahooapis.com/v1/public/yql"); | |
requestUri.addParameter("format", "json"); | |
// tutaj kolejne parametry związane z zapytaniem... | |
HttpGet httpGet = new HttpGet(requestUri.build()); | |
httpGet.addHeader("Authorization", "Bearer " + oauthToken); | |
try (CloseableHttpResponse response = httpclient.execute(httpGet)) { | |
System.out.println(response.getStatusLine()); | |
HttpEntity entity = response.getEntity(); | |
entity.getContent(); | |
//tutaj przetwarzanie odpowiedzi... | |
EntityUtils.consume(entity); | |
} catch (IOException | UnsupportedOperationException e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment