### Blog Search API Request Example (cURL)
Source: https://developers.naver.com/docs/serviceapi/search/blog/blog.md
This example demonstrates how to make a GET request to the Blog Search API using cURL. Ensure you replace the placeholder values with your actual client ID and client secret. The query, display count, start position, and sort order can be customized.
```bash
curl "https://openapi.naver.com/v1/search/blog.xml?query=%EB%A6%AC%EB%B7%B0&display=10&start=1&sort=sim" \
-H "X-Naver-Client-Id: {애플리케이션 등록 시 발급받은 클라이언트 아이디 값}" \
-H "X-Naver-Client-Secret: {애플리케이션 등록 시 발급받은 클라이언트 시크릿 값}" -v
```
--------------------------------
### Example API Call with Access Token
Source: https://developers.naver.com/docs/login/devguide/devguide.md
This example demonstrates how to make a GET request to the user profile API ('/v1/nid/me') using the 'Authorization' header with a Bearer token.
```Shell
curl -XGET "https://openapi.naver.com/v1/nid/me" \
-H "Authorization: Bearer ACCESS_TOKEN"
```
```HTTP
GET /v1/nid/me HTTP/1.1
Host: openapi.naver.com
User-Agent: curl/7.43.0
Accept: */*
Authorization: Bearer ACCESS_TOKEN
```
--------------------------------
### iOS App Not Installed Handling
Source: https://developers.naver.com/docs/utils/mobileapp
A JavaScript example demonstrating how to use a timer to redirect users to the App Store if the Naver App is not detected within a specified time frame on iOS.
```APIDOC
### iOS
While direct execution is possible if the app is installed, a JavaScript timer can be used to redirect to the App Store if it's not. This method (used when the app is not installed) may briefly show an error pop-up before redirecting to the App Store. When setting the timer, assign the timeout ID to `naverAppCheckTimer` for proper handling within Naver App's in-app browser. Below is a script configuration example:
```javascript
```
```
--------------------------------
### News Search API Request Example (XML)
Source: https://developers.naver.com/docs/serviceapi/search/news/news.md
This example demonstrates how to call the News Search API to retrieve news articles. Ensure you replace the placeholder values for X-Naver-Client-Id and X-Naver-Client-Secret with your actual application credentials. The query, display, start, and sort parameters can be adjusted to refine your search.
```http
GET /v1/search/news.xml?query=%EC%A3%BC%EC%8B%9D&display=10&start=1&sort=sim HTTP/1.1
Host: openapi.naver.com
User-Agent: curl/7.49.1
Accept: */*
X-Naver-Client-Id: {애플리케이션 등록 시 발급받은 클라이언트 아이디 값}
X-Naver-Client-Secret: {애플리케이션 등록 시 발급받은 클라이언트 시크릿 값}
```
```curl
curl "https://openapi.naver.com/v1/search/news.xml?query=%EC%A3%BC%EC%8B%9D&display=10&start=1&sort=sim" \
-H "X-Naver-Client-Id: {애플리케이션 등록 시 발급받은 클라이언트 아이디 값}" \
-H "X-Naver-Client-Secret: {애플리케이션 등록 시 발급받은 클라이언트 시크릿 값}" -v
```
--------------------------------
### Image Search API Request Example (XML)
Source: https://developers.naver.com/docs/serviceapi/search/image/image.md
This example demonstrates how to make a GET request to the Image Search API to retrieve results in XML format. Ensure you include your Client ID and Client Secret in the request headers for authentication.
```http
> GET /v1/search/image.xml?query=%EC%A3%BC%EC%8B%9D&display=10&start=1&sort=sim HTTP/1.1
> Host: openapi.naver.com
> User-Agent: curl/7.49.1
> Accept: */*
> X-Naver-Client-Id: {애플리케이션 등록 시 발급받은 클라이언트 아이디 값}
> X-Naver-Client-Secret: {애플리케이션 등록 시 발급받은 클라이언트 시크릿 값}
```
--------------------------------
### HTTP Request Example
Source: https://developers.naver.com/docs/login/payaddress-api/payaddress-api.md
This example shows the structure of an HTTP GET request to the Naver Pay address API, including the host and authorization header.
```http
> GET /v1/nid/payaddress HTTP/2
> Host: openapi.naver.com
> User-Agent: curl/7.64.1
> Accept: */*
> Authorization: Bearer {ACCESS_TOKEN_STRING}
```
--------------------------------
### Node.js Example
Source: https://developers.naver.com/docs/serviceapi/datalab/search/search.md
Example of how to use the Naver DataLab Search API with Node.js.
```APIDOC
## POST https://openapi.naver.com/v1/datalab/search
### Description
Retrieves search trend data based on specified criteria.
### Method
POST
### Endpoint
https://openapi.naver.com/v1/datalab/search
### Request Body
- **startDate** (string) - Required - The start date for the trend data (YYYY-MM-DD).
- **endDate** (string) - Required - The end date for the trend data (YYYY-MM-DD).
- **timeUnit** (string) - Required - The time unit for the data ('date', 'week', 'month').
- **keywordGroups** (array) - Required - An array of keyword groups to search for.
- **groupName** (string) - Required - The name of the keyword group.
- **keywords** (array) - Required - A list of keywords within the group.
- **device** (string) - Optional - The device type ('pc', 'mobile').
- **ages** (array) - Optional - An array of age group codes.
- **gender** (string) - Optional - The gender ('m' for male, 'f' for female).
### Request Example
```json
{
"startDate": "2017-01-01",
"endDate": "2017-04-30",
"timeUnit": "month",
"keywordGroups": [
{
"groupName": "한글",
"keywords": [
"한글",
"korean"
]
},
{
"groupName": "영어",
"keywords": [
"영어",
"english"
]
}
],
"device": "pc",
"ages": [
"1"
],
"gender": "f"
}
```
### Response
#### Success Response (200)
- **response** (object) - Contains the search trend data.
- **data** (array) - An array of trend data objects.
- **date** (string) - The date of the data point.
- **ratio** (number) - The search trend ratio.
#### Response Example
```json
{
"startDate": "2017-01-01",
"endDate": "2017-04-30",
"timeUnit": "month",
"results": [
{
"title": "한글",
"keyword": "한글"
},
{
"title": "한글",
"keyword": "korean"
},
{
"title": "영어",
"keyword": "영어"
},
{
"title": "영어",
"keyword": "english"
}
],
"data": [
{
"date": "2017-01-01",
"data": [
50.1,
25.2,
10.3,
14.4
]
},
{
"date": "2017-02-01",
"data": [
51.2,
26.1,
11.1,
11.6
]
}
]
}
```
```
--------------------------------
### Java Blog Search API Example
Source: https://developers.naver.com/docs/serviceapi/search/blog/blog.md
This Java code demonstrates how to use the Naver Search API to search for blog posts. It includes setting up client credentials, encoding the search query, making a GET request, and handling the response.
```APIDOC
## Java Blog Search API Example
### Description
This Java code demonstrates how to use the Naver Search API to search for blog posts. It includes setting up client credentials, encoding the search query, making a GET request, and handling the response.
### Method
GET
### Endpoint
`https://openapi.naver.com/v1/search/blog?query={search_query}`
### Parameters
#### Query Parameters
- **query** (string) - Required - The search term for blog posts.
#### Request Headers
- **X-Naver-Client-Id** (string) - Required - Your Naver application client ID.
- **X-Naver-Client-Secret** (string) - Required - Your Naver application client secret.
### Request Example
```java
// ... (Java code for setting up query and headers)
String apiURL = "https://openapi.naver.com/v1/search/blog?query=" + text;
Map requestHeaders = new HashMap<>();
requestHeaders.put("X-Naver-Client-Id", clientId);
requestHeaders.put("X-Naver-Client-Secret", clientSecret);
String responseBody = get(apiURL, requestHeaders);
System.out.println(responseBody);
```
### Response
#### Success Response (200)
Returns a JSON object containing search results for blog posts.
#### Response Example
```json
{
"lastBuildDate": "Tue, 19 Mar 2024 10:00:00 +0900",
"total": 100,
"start": 1,
"display": 10,
"items": [
{
"title": "그린팩토리",
"link": "https://blog.naver.com/example/12345",
"description": "This is a description of the blog post about Green Factory.",
"bloggername": "Example Blogger",
"bloggerlink": "https://blog.naver.com/example",
"postdate": "20240318"
}
// ... more items
]
}
```
```
--------------------------------
### Example: Basic Naver App Launch
Source: https://developers.naver.com/docs/utils/mobileapp
These examples show how to launch the Naver app using the basic format for iOS and the redirect page for Android.
```text
naversearchapp://default?version=1
```
```text
http://naverapp.naver.com/default/?version=5
```
--------------------------------
### Simple Call Example
Source: https://developers.naver.com/docs/utils/mobileapp
Examples of how to perform a simple call to the Naver App using both the basic format and the relay page.
```APIDOC
## Simple Call Example
| Command | Version | OS |
|---------|---------|---------|
| default | 1 | iOS |
| default | 5 | Android |
#### Sample
* Basic Format: `naversearchapp://default?version=1` (iOS)
* Relay Page: `http://naverapp.naver.com/default/?version=5` (Android)
```
--------------------------------
### Shopping Search Response Example
Source: https://developers.naver.com/docs/serviceapi/search/shopping/shopping.md
Example of a successful response from the Naver Shopping Search API, showing product details in XML format.
```APIDOC
## Shopping Search Response Example
### Description
This is an example of a successful response from the Naver Shopping Search API. It returns product information in XML format, including details like title, link, image, price, mall name, product ID, and category.
### Response Example
```xml
Naver Open API - shop ::'가방'
http://search.naver.com
Naver Search ResultTue, 04 Oct 2016 13:23:58 +090017161390110허니트립 보스턴백
http://openapi.naver.com/l?AAABWLsQ7CIBRFv+Z1JLzSShkYqLajRmPcG6TQRCgiNunfizdnODnJfX9N2iUMCnoKHYWh/4sSlUtmli7nCExBPRY+bo1xCZaEaTOJ6NWXaKdsSHAB2Lg8gZ2QMmybA0cuqiyx4W0ZZR2KrvJyx2CPV3RQ95fbnDT3r+Fh2kbfz5su7x8wIs7ZjgAAAA==
http://shopping.phinf.naver.net/main_1031546/10315467179.jpg67000허니트립103154671792허니트립패션잡화여행용가방/소품보스턴백
...
```
```
--------------------------------
### Curl Command for Cafe Article Search API
Source: https://developers.naver.com/docs/serviceapi/search/cafearticle/cafearticle.md
This example demonstrates how to use curl to make a GET request to the Cafe Article Search API. Ensure you replace the placeholder values for X-Naver-Client-Id and X-Naver-Client-Secret with your actual credentials.
```bash
curl "https://openapi.naver.com/v1/search/cafearticle.xml?query=%EC%A3%BC%EC%8B%9D&display=10&start=1&sort=sim" \
-H "X-Naver-Client-Id: {애플리케이션 등록 시 발급받은 클라이언트 아이디 값}" \
-H "X-Naver-Client-Secret: {애플리케이션 등록 시 발급받은 클라이언트 시크릿 값}" -v
```
--------------------------------
### Request Header Example
Source: https://developers.naver.com/docs/login/profile/profile.md
This example shows the correct format for the Authorization header when making a request to the Naver API for member profile information.
```http
GET v1/nid/me HTTP/1.1
Host: openapi.naver.com
User-Agent: curl/7.43.0
Accept: */*
Content-Type: application/xml
Authorization: Bearer {네이버 로그인 인증 후 받은 접근 토큰 값}
```
--------------------------------
### Complete Naver Login Initialization and Callback Handling
Source: https://developers.naver.com/docs/login/web/web.md
This comprehensive example initializes the SDK with various settings (button, domain, popup) and includes a callback function to process user profile data after successful authentication.
```html
```
--------------------------------
### GET Request for Local Search (XML)
Source: https://developers.naver.com/docs/serviceapi/search/local/local.md
Example of a GET request to the Local Search API to retrieve results in XML format. Includes query, display count, start position, and sort order.
```http
GET /v1/search/local.xml?query=%EC%A3%BC%EC%8B%9D&display=10&start=1&sort=random HTTP/1.1
Host: openapi.naver.com
User-Agent: curl/7.49.1
Accept: */*
X-Naver-Client-Id: {애플리케이션 등록 시 발급받은 클라이언트 아이디 값}
X-Naver-Client-Secret: {애플리케이션 등록 시 발급받은 클라이언트 시크릿 값}
```
--------------------------------
### Shopping Search API Request Example (XML)
Source: https://developers.naver.com/docs/serviceapi/search/shopping/shopping.md
This example demonstrates how to call the Shopping Search API to retrieve results in XML format. Ensure you include your Client ID and Client Secret in the request headers.
```bash
curl "https://openapi.naver.com/v1/search/shop.xml?query=%EC%A3%BC%EC%8B%9D&display=10&start=1&sort=sim" \
-H "X-Naver-Client-Id: {애플리케이션 등록 시 발급받은 클라이언트 아이디 값}" \
-H "X-Naver-Client-Secret: {애플리케이션 등록 시 발급받은 클라이언트 시크릿 값}" -v
```
--------------------------------
### Blog Search Implementation Example
Source: https://developers.naver.com/docs/serviceapi/search/blog/blog.md
This section provides an example of how to implement blog search using the Naver Search API. The provided code snippets in various languages demonstrate the basic structure for making API requests.
```APIDOC
## Blog Search API Example
### Description
This example demonstrates how to perform a blog search using the Naver Search API. It serves as a template for implementing other search API functionalities.
### Method
GET
### Endpoint
`/v1/search/blog`
### Parameters
#### Query Parameters
- **query** (string) - Required - The search keyword.
- **display** (integer) - Optional - Number of results to display per page (1-100).
- **start** (integer) - Optional - The starting index of the search results (1-1000).
- **sort** (string) - Optional - Sorting order ('sim' for similarity, 'date' for date).
### Request Example (Conceptual)
```
https://openapi.naver.com/v1/search/blog?query=YOUR_QUERY&display=10&start=1&sort=sim
```
### Response
#### Success Response (200)
The response will be in XML format, containing a list of blog posts matching the search query. Key elements include:
- **title**: Title of the blog post.
- **link**: URL to the blog post.
- **description**: A snippet of the blog post content.
- **bloggername**: The name of the blog.
- **bloggerlink**: The URL of the blog.
- **postdate**: The date the post was published.
#### Response Example (XML Snippet)
```xml
Naver Open API - blog ::'리뷰'
http://search.naver.com
Naver Search ResultMon, 26 Sep 2016 10:39:37 +09008714891110명예훼손 없이 리뷰쓰기
http://openapi.naver.com/l?AAABWLyw6CMBREv+ayNJe2UrrogvJwg8aYKGvACiSUalNR/t6azGLO5Mzrrd0moVSQJZDl/6I4KIxGpx9y9P4JNANShXSzHXZLu2q3660Jw2bt0k1+aF1rgFYXfZ+c7j3QorYDkCT4JxuIEEyRUYGcxpGXMeMs3VPBOUEWGXntynUW03k7ohBYfG+mOdRqbPL6E84/apnqgaEAAAA=
명예훼손 없이 리뷰쓰기 우리 블로그하시는 분들께는 꽤 중요한 내용일 수도 있습니다 그것도 주로 리뷰 위주로 블로그를 진행하신 분이라면 더욱 더 말이죠
오늘 포스팅은, 어떻게 하면 객관적이고 좋은 리뷰를... 건짱의 Best Drawing World2http://blog.naver.com/yoonbitgaram20161208
```
### Error Handling
Common error codes for the blog search API include:
- **SE01 (400)**: Incorrect query request. Check the API request URL's protocol and parameters.
- **SE02 (400)**: Invalid display value. Ensure the `display` parameter is within the allowed range (1-100).
- **SE03 (400)**: Invalid start value. Ensure the `start` parameter is within the allowed range (1-1000).
- **SE04 (400)**: Invalid sort value. Check for typos in the `sort` parameter.
- **SE06 (400)**: Malformed encoding. Encode search terms using UTF-8.
- **SE05 (404)**: Invalid search API. Check for typos in the API request URL.
- **SE99 (500)**: System Error. Report internal server errors.
- **403**: API permission denied. Ensure the search API is enabled for your application in the Naver Developers Center.
```
--------------------------------
### Shopping Datalab Device Trend Request Example
Source: https://developers.naver.com/docs/serviceapi/datalab/shopping/shopping.md
Use this example to query shopping search trend data by device. Ensure to include your Naver Client ID and Secret in the request headers.
```bash
curl https://openapi.naver.com/v1/datalab/shopping/category/keyword/device \
--header "X-Naver-Client-Id: {애플리케이션 등록 시 발급받은 클라이언트 아이디 값}" \
--header "X-Naver-Client-Secret: {애플리케이션 등록 시 발급받은 클라이언트 시크릿 값}" \
--header "Content-Type: application/json" \
-d @<(cat < GET /v1/nid/agreement HTTP/2
> Host: openapi.naver.com
> user-agent: curl/7.79.1
> accept: */*
> authorization: Bearer AAAAPIuf0L+qfDkM...ShtfK4pchdk/rc=
< HTTP/2 200
< date: Tue, 07 Dec 2021 09:52:56 GMT
< content-type: application/json;charset=utf-8
```
--------------------------------
### Retrieve Member Profile - Java
Source: https://developers.naver.com/docs/login/profile/profile.md
Example of how to retrieve member profile information using the NAVER Open API in Java. Requires an access token and makes an HTTP GET request.
```java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import java.util.HashMap;
import java.net.MalformedURLException;
import java.io.IOException;
import java.io.InputStream;
public class ApiExamMemberProfile {
public static void main(String[] args) {
String token = "YOUR_ACCESS_TOKEN"; // 네이버 로그인 접근 토큰;
String header = "Bearer " + token; // Bearer 다음에 공백 추가
String apiURL = "https://openapi.naver.com/v1/nid/me";
Map requestHeaders = new HashMap<>();
requestHeaders.put("Authorization", header);
String responseBody = get(apiURL,requestHeaders);
System.out.println(responseBody);
}
private static String get(String apiUrl, Map requestHeaders){
HttpURLConnection con = connect(apiUrl);
try {
con.setRequestMethod("GET");
for(Map.Entry header :requestHeaders.entrySet()) {
con.setRequestProperty(header.getKey(), header.getValue());
}
int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) { // 정상 호출
return readBody(con.getInputStream());
} else { // 에러 발생
return readBody(con.getErrorStream());
}
} catch (IOException e) {
throw new RuntimeException("API 요청과 응답 실패", e);
} finally {
con.disconnect();
}
}
private static HttpURLConnection connect(String apiUrl){
try {
URL url = new URL(apiUrl);
return (HttpURLConnection)url.openConnection();
} catch (MalformedURLException e) {
throw new RuntimeException("API URL이 잘못되었습니다. : " + apiUrl, e);
} catch (IOException e) {
throw new RuntimeException("연결이 실패했습니다. : " + apiUrl, e);
}
}
private static String readBody(InputStream body){
InputStreamReader streamReader = new InputStreamReader(body);
try (BufferedReader lineReader = new BufferedReader(streamReader)) {
StringBuilder responseBody = new StringBuilder();
String line;
while ((line = lineReader.readLine()) != null) {
responseBody.append(line);
}
return responseBody.toString();
} catch (IOException e) {
throw new RuntimeException("API 응답을 읽는데 실패했습니다.", e);
}
}
}
```
--------------------------------
### initialize()
Source: https://developers.naver.com/docs/login/android/android.md
Initializes the Naver login instance with client-specific information.
```APIDOC
## initialize(context, clientId, clientSecret, clientName, callback)
### Description
Sets up the client information for the Naver login instance.
### Method
```
fun initialize(
context: Context,
clientId: String,
clientSecret: String,
clientName: String,
callback: NidOAuthInitializingCallback? = null,
)
```
### Parameters
- **context** (Context) - Required - The Context object to use when initializing the internal storage.
- **clientId** (String) - Required - The client ID obtained after registering your application.
- **clientSecret** (String) - Required - The client secret obtained after registering your application.
- **clientName** (String) - Required - The name of the application to be displayed on the Naver app's login screen. (If using the mobile web login screen, the application name stored on the server will be displayed.)
- **callback** (NidOAuthInitializingCallback?) - Optional - A callback for initialization completion and failure. Refer to NidOAuthInitializingCallback for more details.
### Return Value
None
### Code Example
```kotlin
NidOAuth.initialize(context, clientId, clientSecret, clientName, callback)
```
```
--------------------------------
### C# Blog Search Implementation
Source: https://developers.naver.com/docs/serviceapi/search/blog/blog.md
Example of implementing blog search using the Naver Search API in C#. Ensure you replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with your application's credentials.
```csharp
using System;
using System.Text;
using System.Net.Http;
using System.Threading.Tasks;
public class Example
{
public static async Task Main(string[] args)
{
var clientId = "YOUR_CLIENT_ID";
var clientSecret = "YOUR-CLIENT-SECRET";
var searchText = "YOUR_SEARCH_TEXT";
var url = $
```
--------------------------------
### PHP - Captcha Key Generation Request
Source: https://developers.naver.com/docs/utils/captcha/examples
This PHP example shows how to request a captcha key from the Naver Captcha API. It uses cURL to send a GET request with your client ID and secret.
```APIDOC
## 캡차 키 발급 요청
### Description
This PHP script requests a unique captcha key from the Naver Captcha API. This key is necessary for subsequent requests to fetch captcha images or validate user input.
### Method
GET
### Endpoint
`https://openapi.naver.com/v1/captcha/nkey?code=0`
### Parameters
#### Query Parameters
- **code** (string) - Required - Set to '0' to request a new captcha key.
#### Headers
- **X-Naver-Client-Id** (string) - Required - Your Naver application Client ID.
- **X-Naver-Client-Secret** (string) - Required - Your Naver application Client Secret.
### Request Example
```php
```
### Response
#### Success Response (200)
Returns a JSON object containing the captcha key. The key is typically a string value that should be stored and used for subsequent API calls.
#### Response Example
```json
{
"key": "YOUR_CAPTCHA_KEY"
}
```
```
--------------------------------
### Retrieve Member Profile - Node.js
Source: https://developers.naver.com/docs/login/profile/profile.md
Example of how to retrieve member profile information using the NAVER Open API in Node.js with Express. It makes an HTTP GET request using the 'request' library.
```javascript
var express = require('express');
var app = express();
var token = "YOUR_ACCESS_TOKEN";
var header = "Bearer " + token; // Bearer 다음에 공백 추가
app.get('/member', function (req, res) {
var api_url = 'https://openapi.naver.com/v1/nid/me';
var request = require('request');
var options = {
url: api_url,
headers: {'Authorization': header}
};
request.get(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
res.writeHead(200, {'Content-Type': 'text/json;charset=utf-8'});
res.end(body);
} else {
console.log('error');
if(response != null) {
res.status(response.statusCode).end();
console.log('error = ' + response.statusCode);
}
}
});
});
app.listen(3000, function () {
console.log('http://127.0.0.1:3000/member app listening on port 3000!');
});
```
--------------------------------
### Java Blog Search Implementation
Source: https://developers.naver.com/docs/serviceapi/search/blog/blog.md
Example of implementing blog search using the Naver Search API in Java. Ensure you replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with your application's credentials.
```java
String clientId = "YOUR_CLIENT_ID";
String clientSecret = "YOUR-CLIENT-SECRET";
String text = "YOUR_SEARCH_TEXT";
String apiURL = "https://openapi.naver.com/v1/search/blog?query="+ text;
try {
URL url = new URL(apiURL);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("X-Naver-Client-Id", clientId);
con.setRequestProperty("X-Naver-Client-Secret", clientSecret);
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);
}
```
--------------------------------
### Retrieve Member Profile - PHP
Source: https://developers.naver.com/docs/login/profile/profile.md
Example of how to retrieve member profile information using the NAVER Open API in PHP. Utilizes cURL to make an HTTP GET request with an authorization header.
```php
";
curl_close ($ch);
if($status_code == 200) {
echo $response;
} else {
echo "Error 내용:".$response;
}
?>
```
--------------------------------
### PHP Blog Search Implementation
Source: https://developers.naver.com/docs/serviceapi/search/blog/blog.md
Example of implementing blog search using the Naver Search API in PHP. Ensure you replace YOUR_CLIENT_ID and YOUR_CLIENT_SECRET with your application's credentials.
```php
$clientId = "YOUR_CLIENT_ID";
$clientSecret = "YOUR-CLIENT-SECRET";
$text = "YOUR_SEARCH_TEXT";
$encText = urlencode($text);
$apiURL = "https://openapi.naver.com/v1/search/blog?query=".$encText;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Naver-Client-Id:" . $clientId , "X-Naver-Client-Secret:" . $clientSecret));
$response = curl_exec ($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($code == 200) {
echo "
" . $response . "
";
} else {
echo "Error: " . $code;
}
c_url_close($ch);
```
--------------------------------
### Node.js: Request Captcha Image
Source: https://developers.naver.com/docs/utils/captcha/examples
This Node.js example shows how to fetch a captcha image using a provided key and save it to a file, while also piping it to the response. It requires an Express server setup.
```javascript
var express = require('express');
var app = express();
var client_id = 'YOUR_CLIENT_ID';//개발자센터에서 발급받은 Client ID
var client_secret = 'YOUR_CLIENT_SECRET'; //개발자센터에서 발급받은 Client Secret
var fs = require('fs');
app.get('/captcha/image', function (req, res) {
var api_url = 'https://openapi.naver.com/v1/captcha/ncaptcha.bin?key=' + req.query.key;
var request = require('request');
var options = {
url: api_url,
headers: {'X-Naver-Client-Id':client_id, 'X-Naver-Client-Secret': client_secret}
};
var writeStream = fs.createWriteStream('./captcha.jpg');
var _req = request.get(options).on('response', function(response) {
console.log(response.statusCode) // 200
console.log(response.headers['content-type'])
});
_req.pipe(writeStream); // file로 출력
_req.pipe(res); // 브라우저로 출력
});
app.listen(3000, function () {
console.log('http://127.0.0.1:3000/captcha/image?key=캡차키 app listening on port 3000!');
});
```
--------------------------------
### Get Kin Search Results
Source: https://developers.naver.com/docs/serviceapi/search/kin/kin.md
Retrieves search results from Naver's Kin (Q&A) service. You can specify the output format (XML or JSON), the number of results to display, the starting position, and the sorting order.
```APIDOC
## GET /v1/search/kin
### Description
Retrieves search results from Naver's Kin (Q&A) service in either XML or JSON format.
### Method
GET
### Endpoint
`https://openapi.naver.com/v1/search/kin.xml` (for XML)
`https://openapi.naver.com/v1/search/kin.json` (for JSON)
### Parameters
#### Query Parameters
- **query** (String) - Required - The search keyword. Must be UTF-8 encoded.
- **display** (Integer) - Optional - The number of search results to display per page (default: 10, max: 100).
- **start** (Integer) - Optional - The starting position of the search results (default: 1, max: 1000).
- **sort** (String) - Optional - The sorting order for the search results. Options are:
- `sim`: Relevance-based sorting (default).
- `date`: Date-based sorting.
- `point`: Score-based sorting.
### Request Example
```bash
curl "https://openapi.naver.com/v1/search/kin.xml?query=%EC%A3%BC%EC%8B%9D&display=10&start=1&sort=sim" \
-H "X-Naver-Client-Id: {애플리케이션 등록 시 발급받은 클라이언트 아이디 값}" \
-H "X-Naver-Client-Secret: {애플리케이션 등록 시 발급받은 클라이언트 시크릿 값}" -v
```
### Response
#### Success Response (200)
- **rss** (object) - The root element for RSS feed.
- **rss.channel** (object) - Contains metadata and search results.
- **rss.channel.lastBuildDate** (dateTime) - The time when the search results were generated.
- **rss.channel.total** (Integer) - The total number of search results.
- **rss.channel.start** (Integer) - The starting position of the search results.
- **rss.channel.display** (Integer) - The number of search results displayed per page.
- **rss.channel.item** (array) - An array of individual search results. In JSON format, this is returned as the `items` property.
- **rss.channel.item.title** (String) - The title of the Kin question. Matching keywords are wrapped in `` tags.
- **rss.channel.item.link** (String) - The URL of the Kin question.
- **rss.channel.item.description** (String) - A summary of the Kin question content. Matching keywords are wrapped in `` tags.
```
--------------------------------
### Naver Book Search API Request with Curl
Source: https://developers.naver.com/docs/serviceapi/search/book/book.md
Demonstrates how to make a request to the Naver Book Search API using curl. This example searches for books with '주식' in the title and specifies display and start parameters.
```bash
curl "https://openapi.naver.com/v1/search/book_adv.xml?d_titl=%EC%A3%BC%EC%8B%9D&display=10&start=1" \
-H "X-Naver-Client-Id: {애플리케이션 등록 시 발급받은 클라이언트 아이디 값}" \
-H "X-Naver-Client-Secret: {애플리케이션 등록 시 발급받은 클라이언트 시크릿 값}" -v
```
--------------------------------
### Open in In-App Browser Examples
Source: https://developers.naver.com/docs/utils/mobileapp
Examples demonstrating how to open specific URLs within the Naver App's in-app browser, with options to open in a new tab, replace the current one, or load in the current page.
```APIDOC
## Open in In-App Browser Examples
Naver App's in-app browser can open specific URLs. The following are alternative URL codes for entering URL information:
| Encoded Character | Original Character |
|-------------------|--------------------|
| %26 | & |
| %2F | / |
| %3A | : |
| %3F | ? |
| %3D | = |
| Feature | Command | Parameter=Option | Version | OS |
|-----------------------------------------------|----------------|----------------------------------|---------|-------|
| Add as a new window | inappbrowser | url={enter URL}&target=new | 6 | Common|
| Delete existing window and create new one | inappbrowser | url={enter URL}&target=replace | 6 | Common|
| Load URL in the last viewed window (added to history) | inappbrowser | url={enter URL}&target=inpage | 6 | Common|
#### Sample
* Basic Format: `naversearchapp://inappbrowser?url=http%3A%2F%2Fm.naver.com&target=new&version=6`
* Relay Page: `http://naverapp.naver.com/inappbrowser/?url=http%3A%2F%2Fm.naver.com&target=new&version=6`
```