네이버 API를 이용한 네이버 상품 최저가 구하기
최근에 네이버 최저가 구하는걸 만들어 달라고 요청이 와서 만들어 봤습니다.
public function NaverSearch($str)
{
$encText = urlencode($str);
$url = "https://openapi.naver.com/v1/search/shop?query=".$encText."&display=5&sort=asc&filter=naverpay";
$is_post = false;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, $is_post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = "X-Naver-Client-Id: ".NAVER_Client_ID;
$headers[] = "X-Naver-Client-Secret: ".NAVER_Client_Secret;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec ($ch); //응답 값
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //응답 코드
curl_close ($ch);
if($status_code == 200) {
return "{\"result\":\"".$status_code."\",\"data\":" .$response ."}";
}else{
return "{\"result\":\"0\"}";
}
}
네이버 클라이언트 키와 시크릿키는 네이버 개발자센터에서 받으면 됩니다.
결과값이 오류가 나도 결과 값이 나오게 처리 한 부분이 마지막 부분입니다.
댓글 10개
게시판 목록
그누보드5 팁자료실
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 공지 | 3년 전 | 4416 | ||
| 2274 | 2년 전 | 2066 | ||
| 2273 |
|
2년 전 | 1487 | |
| 2272 | 2년 전 | 2468 | ||
| 2271 | 2년 전 | 2069 | ||
| 2270 |
|
2년 전 | 2090 | |
| 2269 |
|
2년 전 | 1891 | |
| 2268 | 2년 전 | 3850 | ||
| 2267 | 2년 전 | 2899 | ||
| 2266 |
|
2년 전 | 2123 | |
| 2265 | 2년 전 | 1642 | ||
| 2264 | 2년 전 | 2123 | ||
| 2263 | 2년 전 | 1992 | ||
| 2262 | 2년 전 | 1540 | ||
| 2261 |
|
2년 전 | 1452 | |
| 2260 | 2년 전 | 2441 | ||
| 2259 |
welcome
|
2년 전 | 1778 | |
| 2258 |
welcome
|
2년 전 | 1307 | |
| 2257 | 2년 전 | 3055 | ||
| 2256 | 2년 전 | 1317 | ||
| 2255 |
|
2년 전 | 1825 | |
| 2254 | 2년 전 | 1797 | ||
| 2253 |
welcome
|
2년 전 | 1571 | |
| 2252 |
welcome
|
2년 전 | 1341 | |
| 2251 | 2년 전 | 2396 | ||
| 2250 | 2년 전 | 2032 | ||
| 2249 | 2년 전 | 1818 | ||
| 2248 | 2년 전 | 1630 | ||
| 2247 | 2년 전 | 2055 | ||
| 2246 | 2년 전 | 2466 | ||
| 2245 | 2년 전 | 1918 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기