search
    • PDF

    search

    • PDF

    Article Summary

    개요

    입력된 주제어와 해당하는 검색어 그룹에 대하여 네이버 통합검색에 대한 기간별 트렌드 데이터를 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-Typeapplication/json
    Content-Type: application/json

    요청 바디

    요청 변수명타입필수 여부설명
    startDatestringY구간 시작 날짜(2016.01.01부터 제공)
    endDatestringY구간 종료 날짜
    timeUnitstringY구간 단위(date, week, month)
    keywordGroupsarray(json)Y주제어, 검색어 그룹(최대 5 개 그룹 지원)
    groupNamestringY주제어(검색어 그룹핑)
    keywordsarray(json)Y해당 그룹에 속하는 검색어 리스트(그룹당 최대 20 개 검색어 지원)
    devicestringNPC/모바일 필터 : pc/mo
    genderstringN성별 필터 : m/f
    agesarray(json)N나이 필터 : 1~11, 구간 정보는 아래 참조

    나이 필터 구간(ages)

    구분범위
    10-12 세
    213-18 세
    319-24 세
    425-29 세
    530-34 세
    635-39 세
    740-44 세
    845-49 세
    950-54 세
    1055-59 세
    1160 세 이상

    응답

    응답 바디

    필드 그룹필드명설명
    startDate구간 시작 날짜 (2016.01.01부터 제공)
    endDate구간 종료 날짜
    timeUnit구간 단위
    resultstitle그룹 주제어
    resultskeywords그룹 검색어 목록
    results.dataperiod구간별 시작 날짜
    results.dataratio구간별 검색/클릭 수치 비율
    (결과 수치 중에 가장 큰 값을 100로 설정한 상대값)

    예시

    요청 예시

    curl https://naveropenapi.apigw-pub.fin-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-pub.fin-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-pub.fin-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-pub.fin-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-pub.fin-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-pub.fin-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-pub.fin-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 코드오류 메시지
    400400잘못된 요청
    500500서버 내부 오류

    이 문서가 도움이 되었습니까?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.