-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchBook.php
28 lines (28 loc) · 965 Bytes
/
searchBook.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
$client_id = "U8NqauK8PCRx6_K4U49W";
$client_secret = "zcsyrPjth5";
$title = $_POST['search'];
$encText = urlencode($title);
$url = "https://openapi.naver.com/v1/search/book.json?query=".$encText; // json 결과
// $url = "https://openapi.naver.com/v1/search/blog.xml?query=".$encText; // xml 결과
$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: ".$client_id;
$headers[] = "X-Naver-Client-Secret: ".$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);
echo "status_code:".$status_code."
";
curl_close ($ch);
if($status_code == 200) {
echo $response;
} else {
echo "Error 내용:".$response;
}
?>