페이지 이동경로
  • Docs>
  • Kakao Talk Social

Kakao Talk Social

Legacy Android

This document describes how to implement the features of Kakao Talk Social in other applications with the Legacy Kakao SDK for Android (hereinafter referred to as Legacy Android SDK).

IMPORTANT

To use Android SDK, you must register the Android platform in advance. Go to [My Application] > [Platform] and register the Android platform by specifying its package name and key hashes.

Retrieve Kakao Talk profile

You can get the Kakao Talk profile of the user currently logged in. Call the requestProfile method in the KakaoTalkService class. When you call this method, you must implement and pass TalkResponseCallback.

requestProfile
Name Type Description
KakaoTalkResponseCallback KakaoTalkProfile Callback to get and proceed Kakao Talk profile.
KakaoTalkService.getInstance()
        .requestProfile(new TalkResponseCallback<KakaoTalkProfile>() {
            @Override
            public void onNotKakaoTalkUser() {
                Log.e("KAKAO_API", "Not a Kakao Talk user.");
            }

            @Override
            public void onSessionClosed(ErrorResult errorResult) {
                Log.e("KAKAO_API", "Session is closed.: " + errorResult);
            }

            @Override
            public void onFailure(ErrorResult errorResult) {
                Log.e("KAKAO_API", "Failed to retrieve Kakao Talk profile.: " + errorResult);
            }

            @Override
            public void onSuccess(KakaoTalkProfile result) {
                Log.i("KAKAO_API", "Kakao Talk nickname: " + result.getNickName());
                Log.i("KAKAO_API", "Kakao Talk profile image: " + result.getProfileImageUrl());
            }
        });

If the request succeeds, the response returns through the KakaoTalkProfile object that contains the nickname, , thumbnail image, and country code of Kakao Talk.

KakaoTalkProfile
Name Type Description
nickName String Kakao Talk nickname.
profileImageUrl String Kakao Talk profile image URL with a size of 640x640 pixels.
Only HTTPS is supported.
thumbnailUrl String Kakao Talk profile thumbnail image URL with a size of 110x110 pixels.
Only HTTPS is supported.
countryISO String A country where the user is using Kakao Talk.

Retrieve list of friends

If there are many Kakao Talk friends on the list, the data is processed with a paging by requestAppFriends to avoid this API overload. Thus, you must create the AppFriendContext context and specify the values to filter the friends information to be retrieved. You must also pass TalkResponseCallback to handle the request result.

requestAppFriends
Name Type Description
friendContext AppFriendContext Used for data filtering to retrieve a list of friends.
TalkResponseCallback AppFriendsResponse Callback to get and proceed a list of friends.
AppFriendContext
Name Type Description
offset Int Offset value that the list of friends starts from.
limit Int Maximum number of friends to be retrieved per page.
(Maximum: 100)
order String Sort order of friends list.
asc or desc.
- asc: sort in ascending order.
- desc: sort in descending order.
appFriendOrder AppFriendOrder Sorty type.
You can sort friends in the list by NICKNAME(Kakao Talk nickname) or FAVORITE(favorite friends).
beforeUrl String Previous page URL.
Processed automatically by Kakao SDK.
afterUrl String Next page URL.
Processed automatically by Kakao SDK.
Sample
// Create a context.
//   to retrieve the nicknames from 0(offset=0) to 100(limit=100) in ascending(order=asc) order.
AppFriendContext context =
        new AppFriendContext(AppFriendOrder.NICKNAME, 0, 100, "asc");

// Make a request to retrieve a list of friends.
KakaoTalkService.getInstance()
        .requestAppFriends(context, new TalkResponseCallback<AppFriendsResponse>() {
            @Override
            public void onNotKakaoTalkUser() {
                Log.e("KAKAO_API", "Not a Kakao Talk user.");
            }

            @Override
            public void onSessionClosed(ErrorResult errorResult) {
                Log.e("KAKAO_API", "Session is closed: " + errorResult);
            }

            @Override
            public void onFailure(ErrorResult errorResult) {
                Log.e("KAKAO_API", "Failed to retrieve a list of friends: " + errorResult);
            }

            @Override
            public void onSuccess(AppFriendsResponse result) {
                Log.i("KAKAO_API", "Succeeded in retrieving a list of friends.");

                for (AppFriendInfo friend : result.getFriends()) {
                    Log.d("KAKAO_API", friend.toString());

                    String uuid = friend.getUUID();     // 메시지 전송 시 사용
                }
            }
        });

If the request is successful, a list of friends and reference information return through the AppFriendInfo object that contains the Kakao Talk friends as many as you specified when you request to retrieve.

AppFriendsResponse
Name Type Description
friends List<AppFriendInfo> A list of AppFriendInfo paged.페이징된 AppFriendInfo 리스트
totalCount Int Total number of Kakao Talk friends in the list.
favoriteCount Int Number of favorite friends in the list.
beforeUrl String Previous page URL
afterUrl String Next page URL.
AppFriendInfo
Name Type Description
userId Long Service user ID.
uuid String A user's unique ID used to send a Kakao Talk message.
profileNickname String User profile nickname.
Only HTTPS is supported.
profileThumbnailImage String User profile thumbnail image.
Only HTTPS is supported.
favorite OptionalBoolean Whether to add the friend as a favorite.

The Legacy Android Kakao SDK creates not only the request URLs but also beforeUrl and afterUrl based on you specified in AppFriendContext. Thus, you can retrieve the friends information in the previous and next page by using AppFriendContext without specifying offset and limit.

Rather than calling the next page when the request is successful in the code snippet below, it is recommended to call the object using lazy initialization to avoid over usage and unnecessary API calls. Then, the object is instantiated to request for the next page when users scroll down to the end of the friends list through RecyclerView or ListView.

    // Check the next page and retry the request. 
    if (context.hasNext()) {
        requestNextFriends(context);
    }
}

...

public void requestNextFriends(AppFriendContext context) {
    
    // Re-use the context to retrieve friends list.
    KakaoTalkService.getInstance()
            .requestAppFriends(context, new TalkResponseCallback<AppFriendsResponse>() {

                // Omitted.

            });

See more