Skip to content

Instantly share code, notes, and snippets.

@gshutler
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gshutler/f7c71c63cf8edc3c0a59 to your computer and use it in GitHub Desktop.
Save gshutler/f7c71c63cf8edc3c0a59 to your computer and use it in GitHub Desktop.
Example of retrieving a day's events in Java
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