페이지 이동경로
  • Docs>
  • Tutorial>
  • Test with sample code

Tutorial

Test with sample code

Kakao Developers provides sample code to experience Kakao Login features. This tutorial explains step by step from setting up the development environment to running the code and testing.

Overview

Category Description
Prerequisite Kakao Developers account and app creation

Note: Getting started with Kakao API
Implementation result A webpage where you can test Kakao Login, Logout, Unlink, and retrieving information of the logged-in user

Note: Test webpage screen

1. Prepare development environment

To run the sample code, you must first install the development tools and the software required for the language you want to use. Complete the necessary setup by referring to the installation requirements of your chosen language.

1-1. Prepare required development tools

Item Description
Command Line Interface (CLI) A window to input and execute commands.
Built-in on each operating system, so no additional installation is required.
MacOS: Terminal
Windows: Command Prompt or PowerShell
Code editor (IDE) A required tool for editing environment settings and writing code, usually provides a built-in terminal.
Install your preferred tool, such as Visual Studio Code or Cursor.

1-2. Install development language and tools

You must install the language and related tools to run the sample code.

Check installation

Enter the commands below in the terminal to check whether the for the language or tool you want to use is installed. If its version information is displayed when entering the command, the installation is complete.

# If using Node.js
node -v
npm -v

# If using PHP
php -v

# If using Python
python3 --version 
Minimum requirement

To use the sample code, install the versions specified or higher.

Language Required installation and version
Node.js Node.js 18.x or higher, npm 9.x or higher, Express 4.18.x or higher, axios 1.6.x or higher.
PHP PHP 7.4 or higher recommended. Built-in server is available.
Python Python 3.7 or higher, pip.
Installation

If no version information is displayed, refer to the table below to install the corresponding language.

Target Installation method
Node.js macOS:
- If Homebrew is installed: brew install node
- If Homebrew is not installed: Download and run the macOS installer from the Node.js official site.

Windows:
- Download and run the Windows installer (.msi) from the Node.js official site.

npm is also installed after Node.js is installed.
PHP macOS:
- If Homebrew is installed: brew install php
- If Homebrew is not installed: Download and run the macOS installer from the PHP official site.

Windows:
- Download and extract the Windows installer (.zip) from the PHP official site.
- Or install an integrated package such as XAMPP.
Python macOS:
- If Homebrew is installed: brew install python
- If Homebrew is not installed: Download and run the macOS installer (.pkg) from the Python official site.

Windows:
- Download and run the Windows installer (.exe) from the Python official site.
- It is recommended to check the "Add Python to PATH" option during installation.

After installation is complete, enter the Check installation command again to verify that the installation is successful.

2. Set up project

2-1. Create folder

Enter the following commands in the terminal to create a new project folder and move into it. In this tutorial, configuration files and code files will be created in the kakao-test folder.

mkdir kakao-test
cd kakao-test

2-2. Get sample code

The sample code used in this tutorial and in Implement Kakao Login can be downloaded from the GitHub repositories below.

Language Repository
Node.js GitHub
PHP GitHub
Python GitHub

From each language’s GitHub repository, select [Code] > [Download ZIP] to download the ZIP file. After extracting the downloaded file, open the folder in your code editor.

Or, you can clone the repository using the Git command below and then move to the project folder. (See the GitHub official documentation.) To use this method, you must install Git.

Node.js
PHP
Python
git clone https://github.com/kakao-tam/developers-node.js.git
cd developers-node.js 
git clone https://github.com/kakao-tam/developers-php.git
cd developers-php.git
git clone https://github.com/kakao-tam/developers-python.flask.git
cd developers-python.flask

2-3. Install dependencies

Install the required external libraries. If not installed, an error may occur stating that the module cannot be found when executing the code.

Node.js
PHP
Python
npm install

When executed in the terminal, this command automatically installs all dependencies specified in the package.json file and creates a node_modules folder. The code will run correctly only after this process is completed.

PHP can run without installing additional packages. The file_get_contents or curl function is included by default. If needed, dependencies can also be managed with Composer.

pip install -r requirements.txt

3. Set up app

This section explains the settings required in Kakao Developers to use Kakao Login.

3-1. Create app

To use the Kakao API, you must first create a Kakao Developers app.

For instructions on how to create an app, see Getting started with Kakao API.

3-2. Enable Kakao Login

  1. On the app management page, select the created app. (Go to app management page →)
  2. Under [Kakao Login], select [General].
  3. In [Usage settings], change the [Status] to [ON].

3-3. Register redirect URI

To use Kakao Login, you must register the address (Redirect URI) where the authorization code will be sent after login.

Go to [Kakao Login] > [General] > [Redirect URI] and register the Redirect URI. In this tutorial, the following values are used, but you can register other values as needed.

Language Redirect URI to register
Node.js http://localhost:4000/redirect
PHP http://localhost:4000/api.php?action=redirect
Python http://localhost:4000/redirect
Note

3-4. Set consent items

To allow Kakao to access user information through the API, user consent is required. Configure consent items to request user consent.

  1. On the app management page, select the app you will use, then go to [Kakao Login] > [Consent Items].
  2. In the row of the consent item you want to request, select the [Settings] button.
  3. Configure the [Consent level] and [Purpose of consent], then save. (For details, see Prerequisites)

To configure disabled consent items or consent levels, you must submit a Request permission.

In this tutorial, configure the consent items as follows:

Consent item Consent level Purpose of consent
Nickname Required consent To identify users
Profile image Optional consent To identify users
Friends list in Kakao services Consent during use
To set as optional consent, Request permission is required.
To provide friend invitation and social features
Note

4. Run test code

4-1. Open project in code editor

Open the kakao-test folder in your code editor (IDE). Confirm the project setup is complete as described in Set up project.

4-2. Apply app information

Enter the app information in the configuration file that corresponds to your selected programming language.

  • Node.js: app.js
  • PHP: api.php
  • Python: api.py

Open the corresponding configuration file and replace the client_id value with the REST API key of your app. You can use the other variables as provided in the sample code.

Variable Description
client_id REST API key found in App keys.
domain Domain address used as the server.
(Example: http://localhost:4000)

Important: For test code, an HTTP domain is used, but for real services, HTTPS with a security certificate is recommended.
redirect_uri Registered redirect URI.
(Example: http://localhost:4000/redirect)
client_secret Required if using Client secret (Optional).
Recommended for enhanced security.
(Example: client_secret=xKsfEDskdHdkxYdkx*****)
Example
Node.js
PHP
Python
// app.js

const client_id = "6f95e7e3146********"; // Replace with your REST API key.
const client_secret = "aAbBcD***********"; // Optional: Add if using Client secret.
const domain = "http://localhost:4000";
const redirect_uri = `${domain}/redirect`;
const token_uri = "https://kauth.kakao.com/oauth/token";
const api_host = "https://kapi.kakao.com";
// api.php

$client_id = '6f95e7e3146********';  // Replace with your REST API key.
$client_secret = 'aAbBcD***********'; //Optional: Add if using Client secret.
$domain = 'http://localhost:4000';
$redirect_uri = $domain . '/api.php?action=redirect';
$kauth_host = 'https://kauth.kakao.com';
$kapi_host = 'https://kapi.kakao.com';
# api.py

client_id = "6f95e7e3146********"  # Replace with your REST API key.
client_secret = "aAbBcD***********" # Optional: Add if using Client secret.
domain = "http://localhost:4000"
redirect_uri = domain + "/redirect"
kauth_host = "https://kauth.kakao.com"
kapi_host = "https://kapi.kakao.com"

4-3. Run server

Open the terminal, move to the cloned folder, and enter the command to start the server.

Node.js
PHP
Python
cd developers-node.js 
npm start  
cd developers-php
php -S localhost:4000
cd developers-python.flask
python api.py

4-4. Access web browser

Access the web browser using the address displayed in the terminal, as shown in the examples below.

Node.js
PHP
Python
> kakao-test@1.0.0 start
> node app.js

Server is running at http://localhost:4000
PHP 8.4.7 Development Server (http://localhost:4000) started
* Running on all addresses.
  WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://172.12.34.5:4000/ (Press CTRL+C to quit)
:

5. Test

When you access the web browser, you can see a test webpage like the one below. The page is structured as follows:

Test webpage
Section Description
Login button area A button to log in with Kakao Account. (카카오계정으로 로그인)

Important: If you follow only the steps in this tutorial, the [JavaScript SDK] button will not work. To test it, you need to install and initialize JavaScript SDK.
Basic feature button area Provides buttons to call APIs such as Retrieve profile(프로필 조회), Logout(로그아웃), and Unlink(연결 해제).
Response area Displays the Kakao API response result in JSON format.
Additional feature button area Provides buttons for Retrieve friends list(친구 목록 조회), Send me message(나에게 메시지 전송), and Send friends message(친구에게 메시지 전송).

Important: These features do not work by only following the steps in this tutorial. To use them, you must complete additional setup.
To retrieve the friends list, you need to request permission for Kakao Talk Social.
To send messages to friends, you need to request permission for Kakao Talk Message.

5-1. Login with Kakao Account

When you select [Login with Kakao Account], the code from Implement Kakao Login > 3-3. Get authorization code runs and the Kakao Login screen is displayed.

If you log in with your Kakao Account and grant consent on the consent screen, the code from 3-4. Request access token and save session runs, and you are redirected back to the test webpage. If an error occurs, see Error code.

5-2. Retrieve user information

When you select [친구 목록 조회(Retrieve user information)], the code from Implement Kakao Login > 3-5. Retrieve information of logged-in user runs.

Response example

If the request succeeds, you can check the user information returned by the Kakao API server in the [Response area]. Some fields may not be provided depending on whether the user has consented. That is, only user information that the user has consented to provide is returned.

If the request fails or an error occurs, an error message is also displayed. In such cases, check Error code to identify its cause.

{
  // Service user ID to distinguish the user in the service
  "id": 123456789, 
  // Time when the user connected to the app via Kakao Login
  "connected_at": "2023-10-01T12:34:56Z",
   "properties": {
    "nickname": "Hong Gil-dong",
    "profile_image": "http://.../profile.jpg",
    "thumbnail_image": "http://.../thumb.jpg"
  },
  // User information stored in Kakao Account
  "kakao_account": {
    "email": "hong@example.com",
    "profile": {
      "nickname": "Hong Gil-dong",
      "profile_image_url": "http://.../profile.jpg"
    }
  }
}

5-3. Logout

When you select [Logout], the user is logged out of the app and the access token is revoked.

5-4. Unlink

To test unlinking, log in again. When you select [Unlink], the code from Implement Kakao Login > 3-6. Implement logout and unlink runs, the app and your account is unlinked.

Unlike logout, when the connection is unlinked and the user attempts to log in again, the consent screen is displayed, and the user can reconnect (sign up) to the app.

See more

  • Getting started with Kakao API: This guide walks you through the essential steps for getting started with the Kakao API, from creating your app to making your first API call.
  • Implement Kakao Login: You can learn how to implement the Kakao Login feature with this guide. It covers the full process in Node.js, PHP, and Python.