MENU
      Search Trend examples

        Search Trend examples


        Article summary

        Available in Classic and VPC

        This document introduces examples of using the Search Trend API.

        Search Trend

        This section describes examples of Search Trend API that analyze trend data statistics from NAVER Unified Search by age, gender, and search environment.

        Java

        The following is a Java-based sample code for the Search Trend 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.ntruss.com/datalab/v1/search";
                    String body = "{\"startDate\":\"2017-01-01\",\"endDate\":\"2017-04-30\",\"timeUnit\":\"month\",\"keywordGroups\":[{\"groupName\":\"Korean\",\"keywords\":[\"Korean\",\"korean\"]},{\"groupName\":\"English\",\"keywords\":[\"English\",\"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);
                }
            }
        }
        Java

        Python

        The following is a Python-based sample code for the Search Trend API.

        import os
        import sys
        import urllib.request
        client_id = "YOUR_CLIENT_ID"
        client_secret = "YOUR_CLIENT_SECRET"
        url = "https://naveropenapi.apigw.ntruss.com/datalab/v1/search";
        body = "{\"startDate\":\"2017-01-01\",\"endDate\":\"2017-04-30\",\"timeUnit\":\"month\",\"keywordGroups\":[{\"groupName\":\"Korean\",\"keywords\":[\"Korean\",\"korean\"]},{\"groupName\":\"English\",\"keywords\":[\"English\",\"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)
        Python

        PHP

        The following is a PHP-based sample code for the Search Trend API.

        <?php
        
        $client_id = "YOUR_CLIENT_ID";
        $client_secret = "YOUR_CLIENT_SECRET";
        
        $url = "https://naveropenapi.apigw.ntruss.com/datalab/v1/search";
        $body = "{\"startDate\":\"2017-01-01\",\"endDate\":\"2017-04-30\",\"timeUnit\":\"month\",\"keywordGroups\":[{\"groupName\":\"Korean\",\"keywords\":[\"Korean\",\"korean\"]},{\"groupName\":\"English\",\"keywords\":[\"English\",\"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 content:".$response;
        }
        ?>
        PHP

        JavaScript

        The following is a JavaScript-based sample code for the Search Trend API.

        var request = require('request');
        
        var client_id = 'YOUR_CLIENT_ID';
        var client_secret = 'YOUR_CLIENT_SECRET';
        
        var api_url = 'https://naveropenapi.apigw.ntruss.com/datalab/v1/search';
        var request_body = {
          startDate: '2017-01-01',
          endDate: '2017-04-30',
          timeUnit: 'month',
          keywordGroups: [
            {
              groupName: 'Korean',
              keywords: ['Korean', 'korean'],
            },
            {
              groupName: 'English',
              keywords: ['English', '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);
          },
        );
        JavaScript

        C#

        The following is a C#-based sample code for the Search Trend API.

        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.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\":\"Korean\",\"keywords\":[\"Korean\",\"korean\"]},{\"groupName\":\"English\",\"keywords\":[\"English\",\"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);
                }
            }
        }
        Plain text

        Was this article helpful?

        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.