개요
입력된 주제어와 해당하는 검색어 그룹에 대하여 네이버 통합검색에 대한 기간별 트렌드 데이터를 json 형태로 리턴해주는 REST API입니다.
http://datalab.naver.com/keyword/trendSearch.naver 결과와 동일합니다
요청
요청 파라미터
- 해당 API 는 요청 파라미터를 필요로 하지 않습니다.
요청 헤더
헤더 명 |
설명 |
X-NCP-APIGW-API-KEY-ID |
앱 등록 시 발급받은 Client ID
X-NCP-APIGW-API-KEY-ID:{Client ID} |
X-NCP-APIGW-API-KEY |
앱 등록 시 발급 받은 Client Secret
X-NCP-APIGW-API-KEY:{Client Secret} |
Content-Type |
application/json
Content-Type: application/json |
요청 바디
요청 변수명 |
타입 |
필수 여부 |
설명 |
startDate |
string |
Y |
구간 시작 날짜(2016.01.01부터 제공합니다) |
endDate |
string |
Y |
구간 종료 날짜 |
timeUnit |
string |
Y |
구간 단위(date, week, month) |
keywordGroups |
array(json) |
Y |
주제어, 검색어 그룹(최대 5 개 그룹 지원) |
groupName |
string |
Y |
주제어(검색어 그룹핑) |
keywords |
array(json) |
Y |
해당 그룹에 속하는 검색어 리스트(그룹당 최대 20 개 검색어 지원) |
device |
string |
N |
PC/모바일 필터 : pc /mo |
gender |
string |
N |
성별 필터 : m /f |
ages |
array(json) |
N |
나이 필터 : 1 ~11 , 구간 정보는 아래 참조 |
나이 필터 구간(ages)
구분 |
범위 |
1 |
0-12 세 |
2 |
13-18 세 |
3 |
19-24 세 |
4 |
25-29 세 |
5 |
30-34 세 |
6 |
35-39 세 |
7 |
40-44 세 |
8 |
45-49 세 |
9 |
50-54 세 |
10 |
55-59 세 |
11 |
60 세 이상 |
응답
응답 바디
필드 그룹 |
필드명 |
설명 |
|
startDate |
구간 시작 날짜 (2016.01.01부터 제공합니다.) |
|
endDate |
구간 종료 날짜 |
|
timeUnit |
구간 단위 |
results |
title |
그룹 주제어 |
results |
keywords |
그룹 검색어 목록 |
results.data |
period |
구간별 시작 날짜 |
results.data |
ratio |
구간별 검색/클릭 수치 비율 (결과 수치 중에 가장 큰 값을 100로 설정한 상대값) |
예시
요청 예시
curl https://naveropenapi.apigw.gov-ntruss.com/datalab/v1/search \
--header "X-NCP-APIGW-API-KEY-ID: YOUR_CLIENT_ID" \
--header "X-NCP-APIGW-API-KEY: YOUR_CLIENT_SECRET" \
--header "Content-Type: application/json" \
-d @<(cat <<EOF
{
"startDate": "2017-01-01",
"endDate": "2017-04-30",
"timeUnit": "month",
"keywordGroups": [
{
"groupName": "한글",
"keywords": [
"한글",
"korean"
]
},
{
"groupName": "영어",
"keywords": [
"영어",
"english"
]
}
],
"device": "pc",
"ages": [
"1",
"2"
],
"gender": "f"
}
EOF
)
POST /v1/datalab/search HTTP/1.1
Host: naveropenapi.apigw.gov-ntruss.com
Content-Length: 360
응답 예시
{
"startDate": "2017-01-01",
"endDate": "2017-04-30",
"timeUnit": "month",
"results": [
{
"title": "한글",
"keywords": ["한글", "korean"],
"data": [
{
"period": "2017-01-01",
"ratio": 47.0
},
{
"period": "2017-02-01",
"ratio": 53.23
},
{
"period": "2017-03-01",
"ratio": 100.0
},
{
"period": "2017-04-01",
"ratio": 85.32
}
]
},
{
"title": "영어",
"keywords": ["영어", "english"],
"data": [
{
"period": "2017-01-01",
"ratio": 40.08
},
{
"period": "2017-02-01",
"ratio": 36.69
},
{
"period": "2017-03-01",
"ratio": 52.11
},
{
"period": "2017-04-01",
"ratio": 44.45
}
]
}
]
}
API 예제
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class APIExamDatalabTrend {
public static void main(String[] args) {
String clientId = "YOUR_CLIENT_ID";//애플리케이션 클라이언트 아이디값";
String clientSecret = "YOUR_CLIENT_SECRET";//애플리케이션 클라이언트 시크릿값";
try {
String apiURL = "https://naveropenapi.apigw.gov-ntruss.com/datalab/v1/search";
String body = "{\"startDate\":\"2017-01-01\",\"endDate\":\"2017-04-30\",\"timeUnit\":\"month\",\"keywordGroups\":[{\"groupName\":\"한글\",\"keywords\":[\"한글\",\"korean\"]},{\"groupName\":\"영어\",\"keywords\":[\"영어\",\"english\"]}],\"device\":\"pc\",\"ages\":[\"1\",\"2\"],\"gender\":\"f\"}";
URL url = new URL(apiURL);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("X-NCP-APIGW-API-KEY-ID", clientId);
con.setRequestProperty("X-NCP-APIGW-API-KEY", clientSecret);
con.setRequestProperty("Content-Type", "application/json");
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.write(body.getBytes());
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
BufferedReader br;
if(responseCode==200) { // 정상 호출
br = new BufferedReader(new InputStreamReader(con.getInputStream()));
} else { // 에러 발생
br = new BufferedReader(new InputStreamReader(con.getErrorStream()));
}
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = br.readLine()) != null) {
response.append(inputLine);
}
br.close();
System.out.println(response.toString());
} catch (Exception e) {
System.out.println(e);
}
}
}
<?php
$client_id = "YOUR_CLIENT_ID";
$client_secret = "YOUR_CLIENT_SECRET";
$url = "https://naveropenapi.apigw.gov-ntruss.com/datalab/v1/search";
$body = "{\"startDate\":\"2017-01-01\",\"endDate\":\"2017-04-30\",\"timeUnit\":\"month\",\"keywordGroups\":[{\"groupName\":\"한글\",\"keywords\":[\"한글\",\"korean\"]},{\"groupName\":\"영어\",\"keywords\":[\"영어\",\"english\"]}],\"device\":\"pc\",\"ages\":[\"1\",\"2\"],\"gender\":\"f\"}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = "X-NCP-APIGW-API-KEY-ID: ".$client_id;
$headers[] = "X-NCP-APIGW-API-KEY: ".$client_secret;
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$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;
}
?>
var request = require('request');
var client_id = 'YOUR_CLIENT_ID';
var client_secret = 'YOUR_CLIENT_SECRET';
var api_url = 'https://naveropenapi.apigw.gov-ntruss.com/datalab/v1/search';
var request_body = {
startDate: '2017-01-01',
endDate: '2017-04-30',
timeUnit: 'month',
keywordGroups: [
{
groupName: '한글',
keywords: ['한글', 'korean'],
},
{
groupName: '영어',
keywords: ['영어', 'english'],
},
],
device: 'pc',
ages: ['1', '2'],
gender: 'f',
};
request.post(
{
url: api_url,
body: JSON.stringify(request_body),
headers: {
'X-NCP-APIGW-API-KEY-ID': client_id,
'X-NCP-APIGW-API-KEY': client_secret,
'Content-Type': 'application/json',
},
},
function(error, response, body) {
console.log(response.statusCode);
console.log(body);
},
);
#-*- coding: utf-8 -*-
import os
import sys
import urllib.request
client_id = "YOUR_CLIENT_ID"
client_secret = "YOUR_CLIENT_SECRET"
url = "https://naveropenapi.apigw.gov-ntruss.com/datalab/v1/search";
body = "{\"startDate\":\"2017-01-01\",\"endDate\":\"2017-04-30\",\"timeUnit\":\"month\",\"keywordGroups\":[{\"groupName\":\"한글\",\"keywords\":[\"한글\",\"korean\"]},{\"groupName\":\"영어\",\"keywords\":[\"영어\",\"english\"]}],\"device\":\"pc\",\"ages\":[\"1\",\"2\"],\"gender\":\"f\"}";
request = urllib.request.Request(url)
request.add_header("X-NCP-APIGW-API-KEY-ID",client_id)
request.add_header("X-NCP-APIGW-API-KEY",client_secret)
request.add_header("Content-Type","application/json")
response = urllib.request.urlopen(request, data=body.encode("utf-8"))
rescode = response.getcode()
if(rescode==200):
response_body = response.read()
print(response_body.decode('utf-8'))
else:
print("Error Code:" + rescode)
using System;
using System.Net;
using System.Text;
using System.IO;
namespace NaverAPI_Guide
{
public class APIExamDatalabTrend
{
static void Main(string[] args)
{
string url = "https://naveropenapi.apigw.gov-ntruss.com/datalab/v1/search";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("X-NCP-APIGW-API-KEY-ID", "YOUR-CLIENT-ID");
request.Headers.Add("X-NCP-APIGW-API-KEY", "YOUR-CLIENT-SECRET");
request.ContentType = "application/json";
request.Method = "POST";
string body = "{\"startDate\":\"2017-01-01\",\"endDate\":\"2017-04-30\",\"timeUnit\":\"month\",\"keywordGroups\":[{\"groupName\":\"한글\",\"keywords\":[\"한글\",\"korean\"]},{\"groupName\":\"영어\",\"keywords\":[\"영어\",\"english\"]}],\"device\":\"pc\",\"ages\":[\"1\",\"2\"],\"gender\":\"f\"}";
byte[] byteDataParams = Encoding.UTF8.GetBytes(body);
request.ContentLength = byteDataParams.Length;
Stream st = request.GetRequestStream();
st.Write(byteDataParams, 0, byteDataParams.Length);
st.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream, Encoding.UTF8);
string text = reader.ReadToEnd();
stream.Close();
response.Close();
reader.Close();
Console.WriteLine(text);
}
}
}
에러 코드
에러 코드 |
HTTP 코드 |
에러 메시지 |
400 |
400 |
잘못된 요청 |
500 |
500 |
서버 내부 오류 |