Last active
August 29, 2015 14:09
-
-
Save gshutler/f7c71c63cf8edc3c0a59 to your computer and use it in GitHub Desktop.
Example of retrieving a day's events in Java
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
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
public final class Example { | |
public static void main(String[] args) throws IOException { | |
String url = "https://api.onediary.com/v1/events?from=2014-12-17&to=2014-12-18&tzid=Europe/Lisbon"; | |
String token = "REPLACE_WITH_YOUR_TOKEN"; | |
URL obj = new URL(url); | |
HttpURLConnection con = (HttpURLConnection) obj.openConnection(); | |
con.setRequestMethod("GET"); | |
con.setRequestProperty("Authorization", String.format("Bearer %s", token)); | |
int responseCode = con.getResponseCode(); | |
InputStreamReader responseStreamReader = new InputStreamReader(con.getInputStream()); | |
BufferedReader responseReader = new BufferedReader(responseStreamReader); | |
String inputLine; | |
StringBuffer response = new StringBuffer(); | |
while ((inputLine = responseReader.readLine()) != null) { | |
response.append(inputLine); | |
} | |
responseReader.close(); | |
responseStreamReader.close(); | |
System.out.println(String.format("Response code: %s", responseCode)); | |
System.out.println(response.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment