| 서비스 | 서비스명 | 국내외 일일정보 | 서비스유형 | OPEN API |
|---|---|---|---|---|
| 최종수정일 | 2024-07-18 | 업데이트주기 | 상시 | |
| 최초개방일 | 2024-07-18 | API호출제한 | 분당 30회 | |
| 제공기관 | 기관 | 식품안전정보원 | 분류 | 식품안전정보 |
| 설명 | 데이터 설명 | 식품안전정보원이 수집·제공하는 식품안전정보 | ||
| 속성정보 | 출력 순번, 제목, 등록일, 국가, 정보구분, 내용, 원문 URL | |||
| 비고 | ||||
| 이용허락범위 | 제한없음 | |||
| 요청주소 | JSON | URL | https://api.foodinfo.or.kr/api/foodinfo/daily/json | ||
|---|---|---|---|---|---|
| SAMPLE | https://api.foodinfo.or.kr/api/foodinfo/daily/sample/json | ||||
| XML | URL | https://api.foodinfo.or.kr/api/foodinfo/daily/xml | |||
| SAMPLE | https://api.foodinfo.or.kr/api/foodinfo/daily/sample/xml | ||||
| URL설명 | JSON | 기본 | https://api.foodinfo.or.kr/api/foodinfo/daily/json?apiKey=인증키&bgnde=요청시작일&endde=요청종료일 | ||
| 추가요청인자적용 | https://api.foodinfo.or.kr/api/foodinfo/daily/json?apiKey=인증키&bgnde=요청시작일&endde=요청종료일&startIndex=요청시작위치&endIndex=요청종료위치 | ||||
| 예시 | https://api.foodinfo.or.kr/api/foodinfo/daily/json?apiKey=sampleKey&bgnde=20240101&endde=20241231&startIndex=1&endIndex=100 | ||||
| XML | 기본 | https://api.foodinfo.or.kr/api/foodinfo/daily/xml?apiKey=인증키&bgnde=요청시작일&endde=요청종료일 | |||
| 추가요청인자적용 | https://api.foodinfo.or.kr/api/foodinfo/daily/xml?apiKey=인증키&bgnde=요청시작일&endde=요청종료일&startIndex=요청시작위치&endIndex=요청종료위치 | ||||
| 예시 | https://api.foodinfo.or.kr/api/foodinfo/daily/xml?apiKey=sampleKey&bgnde=20240101&endde=20241231&startIndex=1&endIndex=100 | ||||
| 번호 | 변수명 | 타입 | 필수여부 | 변수설명 | 입력값설명 |
|---|---|---|---|---|---|
| 1 | apiKey | String | Y | 인증키 | 발급 받은 API-KEY(인증키) |
| 2 | startIndex | int | N | 요청 시작 위치 | 정수입력(기본값: 1) |
| 3 | endIndex | int | N | 요청 종료 위치 | 정수입력(기본값: 10) |
| 4 | bgnde | String | Y | 요청 시작일 | 시작일(yyyyMMdd) 입력 |
| 5 | endde | String | Y | 요청 종료일 | 종료일(yyyyMMdd) 입력 |
| 번호 | 항목 | 설명 |
|---|---|---|
| 1 | ID | 출력 순번 |
| 2 | TITLE | 제목 |
| 3 | REGISTRATION_DATE | 등록일 |
| 4 | COUNTRY | 국가 |
| 5 | INFO_TYPE | 정보구분 |
| 6 | CONTENT | 내용 |
| 7 | ORIGINAL_URL | 원문 URL |
| 번호 | 메시지코드 | 설명 |
|---|---|---|
| 1 | 200 | 정상 처리되었습니다. |
| 2 | 400 | Validation errors occurred |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class ApiExample {
public static void main(String[] args) {
String apiKey = "YOUR_API_KEY";
String apiUrl = "https://api.foodinfo.or.kr/api/foodinfo/daily/json";
String startIndex = "1";
String endIndex = "10";
String bgnde = "20240101";
String endde = "20240131";
try {
URL url = new URL(apiUrl + "?apiKey=" + apiKey + "&startIndex=" + startIndex + "&endIndex=" + endIndex + "&bgnde=" + bgnde + "&endde=" + endde);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Accept", "application/json");
int responseCode = conn.getResponseCode();
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// 응답 출력
System.out.println("Response: " + response.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}