valentin vannay

How to login with Kakao API (PHP)

2016-11-01

I found myself the other day fighting with the Kakao API to implement an easy login function on my web app (PHP). So I thought I'd share here my experience and show you how to quickly achieve this.
By the way, I hope that one day all the Koreans API providers will be smart enough to translater their documentation in english...

Kakao for developers (app creation and settings)

Let's start by setting up your app on the Kakao for developers platform.
1. Go to https://developers.kakao.com/ and login or create an account.
2. Click on the create new App button (앱만들기).
3. Choose a name for your app.
4. On the left menu click on general (일반) and then click on add a platform (플랫폼 추가).
5. Choose the platform you want to work with (in this example we use the web app), so select the option on the right (웹) and enter your website address. Confirm by clicking on the dark grey button (추가).
6. Once the platform has been added you can see you website url and also you can modify the redirect back url. Let's change the default one to something that makes more sense like: kakao_login. Don't forget to confirm by clicking on 전장.
7. Next we have to go utilities admin and "turn on" our app. Toggle the on / off button by clicking on it. Once the app is activated you'll see a bunch of new options to set.
I have to admit that I don't know everything ^^ but I can tell you that you don't need to touch the first part and on the bottom part where there are radio boxes and inputs to fill you can just fill the inputs with anything. Those inputs are the description of why you need to access those services but I haven't seen where exactly does it impact your app yet. By default all the services (kakao talk / kakao story / kakao login etc..) are activated (left radio box checked) but if you don't need everything you can check the radio box on the right that says: don't use. So in my case I only need to access to the profile of the user which is the first input only. And I just wrote for the purpose: "those information are used to login users". And checked the right radio box for the rest.
When you finish don't forget to confirm with the button at the bottom (전장).

The code (PHP)

First create a login button in your HTML code. The URL of your button should be something like this:

The redirect uri is your http://yourdomain/the-callback-we-set-earlier.
Your client ID is the REST API key that you can find in the summary page of your app.
Left menu (개요) then click on 웹키 표시 to display the keys.
Finally create a kakao_login.php page, get the authorize code from the Kakao server, request for an access token and write the code to save in your DB and/or authenticate your users.
Here is a code example to modify according to your needs: (Don't forget to change your app key and redirect url with your information)