메타 데이터의 끝으로 건너뛰기
메타 데이터의 시작으로 이동

이 페이지의 이전 버전을 보고 있습니다. 현재 버전 보기.

현재와 비교 페이지 이력 보기

« 이전 버전 3 다음 »

23.1. KakaoTalk Game Message SDK Example


23.1.1. Setting KakaoTalk Game Message Receipt

This section shows an example of setting up whether the user will receive KakaoTalk game messages.

Unity

using KakaoGame.SDK;
using KakaoGame.SDK.Kakao;
 
// Displaying the setting view for KakaoTalk game message receipt
KGKakaoTalkMessage.ShowAllowMessageSettingView(
    (result, isAllowed) => {
        if (result.isSucces) {
            // KakaoTalk game message receipt setup successful
        }
        else {
            // KakaoTalk game message receipt setup failed
        }
    });

Android

// Displaying the setting view for KakaoTalk game message receipt
KGKakaoTalkMessage.showAllowMessageSettingView(activity, new KGResultCallback<Boolean>() {
    @Override
    public void onResult(KGResult<Boolean> result) {
        if (result.isSuccess()) {
            // KakaoTalk game message receipt setup successful
            boolean allowMessage = result.getContent(); // Configured message receipt option
        } else {
            // KakaoTalk game message receipt setup failed
        }
    }
});

iOS

#import <KakaoGame/KakaoGame.h>
 
// Displaying the setting view for KakaoTalk game message receipt
[KGKakaoTalkMessage showAllowMessageSettingViewWithCompletionHandler:^(NSError *error, BOOL isAllowedMessage) {
    if (IS_SUCCESS(error) == YES)
    {
        // KakaoTalk game message receipt setup successful
        BOOL _isAllowedMessage = isAllowedMessage; // Configured message receipt option
    }
    else
    {
        // KakaoTalk game message receipt setup failed
    }
}];

23.1.2. Querying KakaoTalk Game Friend List

This section shows an example of a query of the KakaoTalk game friend list.

Unity

using Kakaogame.SDK;
 
KGPlayer.LoadFriendPlayers(
    (result, players) => {
        if (result.isSuccess) {
            // Query of KakaoTalk game friend list successful.
            foreach(var player in players) {
                var kakaoProfile = (KGKakaoProfile)player.idpProfile; // Used for sending a game message
            }
        }
        else {
            // Query of KakaoTalk game friend list failed.
        }
    });

Android

// Querying KakaoTalk Game Friend List
KGPlayer.loadFriendPlayers(new KGResultCallback<List<KGPlayer>>() {
    @Override
    public void onResult(KGResult<List<KGPlayer>> result) {
        if (result.isSuccess()) {
            // Request successful
 
            // Friend list
            List<KGPlayer> friendList = result.getContent();
  
            for (KGPlayer player : friendList) {
                KGKakaoProfile profile = (KGKakaoProfile) player.getIdpProfile(); // Used for sending a game message
            }
        } else {
            // Request failed
        }
    }
});

iOS

#import <KakaoGame/KakaoGame.h>
 
// Querying KakaoTalk Game Friend List
 [KGPlayer loadFriendPlayersWithCompletionHandler:^(NSError *error, NSArray *players) {
    if (IS_SUCCESS(error) == YES)
    {
        // Query of KakaoTalk game friend list successful
        for(KGPlayer *player in players)
        {
            KGKakaoProfile *kakaoProfile = (KGKakaoProfile *)player.idpProfile; // Used for sending a game message.
        }
    }
    else
    {
        // Query of KakaoTalk game friend list failed
    }
}];

23.1.3. Sending a KakaoTalk Game Message

This section shows an example of KakaoTalk game message sending.  (Guide : 20. Kakaotalk Message Template V2 )

If you want to receive certain parameters when entering the game by touching the received message, you can set and use the exec parm in the message template.

When you receive the message with KakaoTalk and touch the link to the app, the app is executed and the exec param is passed.

You can use this value to start a specific stage or pay a predefined item. The exec parm can only use game messages.

 

Unity Example

using Kakaogame.SDK;
KGKakaoProfile kakaoProfile; // Kakaotalk profile(KGKakaoProfile Object)
  
// Check if the user allows to receive a game message
if (kakaoProfile.isAllowedMessage == false)
{
    // The user doesn't allow to receive a game message. Don't send the message.
    return;
}
string templateId = "4101";
Dictionary<string, object> argumentDic = new Dictionary<string, object>() {
    {"nickname", "kakao_nickname"}
};
KGKakaoTalkMessage.SendNewGameMessage(
    kakaoProfile,
    templateId,
    argumentDic,
    (result) => {
        if (result.isSuccess) {
            // kakaoTalk game message sent successfully.
        }
        else if (result.code == KGResultCode.MessageSettingDisabled) {
            // If the recipient has opted-out of the message.
        }
        else if (result.code == KGResultCode.ExceedDailyUsage) {
            // Occurs when there is a day's quota (regardless of recipient) that one person can send for a particular app.
        }
        else if (result.code == KGResultCode.ExceedMonthlyUsage) {
            // Occurs when one month exceeds a month's quota that a specific person can send to a particular app.
        }
        else {
            // KakaoTalk game message sent fail.
        }
    });

Android Example

// [TODO] Get my Kakao profile information from my Friends list
KGKakaoProfile kakaoProfile;
  
// Check if the user allows to receive a game message
if (kakaoProfile.isAllowedMessage() == false) {
    // The user doesn't allow to receive a game message. Don't send the message.
    return;
}
// [TODO] Set game message template ID
String templateId;
// [TODO] Add required arguments
Map<String, String> args = new LinkedHashMap<String, String>();
String nickname = ((KGKakaoProfile)KGLocalPlayer.getCurrentPlayer().getIdpProfile()).getNickname();
args.put("${sender_name}", nickname);
  
// Send a Kakaotalk game message
KGKakaoTalkMessage.sendNewGameMessage(kakaoProfile, templateId, args, new KGResultCallback<Boolean>() {
@Override
public void onResult(KGResult<Boolean> result) {
  if (result.isSuccess()) {
   // kakaoTalk game message sent successfully.
  } else {
   // KakaoTalk game message sent fail
   if (result.getCode() == KGResult.KGResultCode.MESSAGE_SETTING_DISABLE) {
    // If the recipient has opted-out of the message.
   } else if (result.getCode() == KGResult.KGResultCode.EXCEED_DAILY_USAGE) {
    // Occurs when there is a day's quota (regardless of recipient) that one person can send for a particular app.
   } else if (result.getCode() == KGResult.KGResultCode.EXCEED_MONTHLY_USAGE) {
    // Occurs when one month exceeds a month's quota that a specific person can send to a particular app.
   } else {
    // etc
   }
  }
}
});

 

 

iOS Example

#import <KakaoGame/KakaoGame.h>
// [TODO] Get my Kakao profile information from my Friends list
KGKakaoProfile *kakaoProfile; // Kakaotalk profile(KGKakaoProfile Object)
  
if (kakaoProfile.isAllowedMessage == NO)
{
    // The user doesn't allow to receive Send a game message. Don't send the message.
    return;
}
// [TODO] Set game message template ID
NSString *templateId = @"4101";
// [TODO] Add required arguments
NSDictionary* argumentDic = @{@"msg":@"This is a game message.", @"iphoneMarketParam":@"test", @"iphoneExecParam":@"test", @"sender_name" : @"iOSTester"};
  
// Send a Kakaotalk game message
[KGKakaoTalkMessage sendNewGameMessageWithKakaoProfile:kakaoProfile
                                            templateId:templateId
                                           argumentDic:argumentDic
                                     completionHandler:^(NSError *error) {
    if (IS_SUCCESS(error) == YES)
    {
        // kakaoTalk game message sent successfully.
    }
    else
    {
        // KakaoTalk game message sent fail
        if (error.code == KGErrorMessageSettingDisabled)
        {
            // If the recipient has opted-out of the message.
        }
        else if (error.code == KGErrorExceedDailyUsage)
        {
            // Occurs when there is a day's quota (regardless of recipient) that one person can send for a particular app.
        }
        else if (error.code == KGErrorExceedMonthlyUsage)
        {
            // Occurs when one month exceeds a month's quota that a specific person can send to a particular app.
        }
        else
        {
            // etc
        }
    }
}];


23.1.4. Sending a KakaoTalk game image message

This is an example of sending a KakaoTalk game image message. (Guide :20. Kakaotalk Message Template V2 )

[Android] Using a dangerous permission feature

If you want to use this feature, you need to add the READ_EXTERNAL_STORAGE permission to Android Manifest.

Android 6.0+ games may use this feature after the user's permission is obtained, using the guide on the notification of individual rights and right request.

Unity Example

using Kakaogame.SDK;
KGKakaoProfile kakaoProfile; // Kakaotalk profile(KGKakaoProfile Object)
  
// Check if the user allows to receive a game message
if (kakaoProfile.isAllowedMessage == false)
{
    // The user doesn't allow to receive a game message. Don't send the message.
    return;
}
// [TODO] Set image file
Texture2D file;
// Upload an image to get the image url
KGKakaoTalk.UploadGameImage(file, (result, imageUrl) => {
    if (result.isSuccess)
    {
        // Pass in the key specified in the message template
        string templateId = "4101";
        string nickname = ((KGKakaoProfile)KGLocalPlayer.currentPlayer.idpProfile).nickname;
        Dictionary<string, object> argumentDic = new Dictionary<string, object>() {
            {"${sender_name}", nickname}
            {"${first_image}", imageUrl}
        };
    
        KGKakaoTalkMessage.SendNewGameMessage(kakaoProfile, templateId, argumentDic, (result) => {
            if (result.isSuccess)
            {
                // kakaoTalk game message sent successfully.
            }
            else if (result.code == KGResultCode.MessageSettingDisabled)
            {
                // If the recipient has opted-out of the message.
            }
            else if (result.code == KGResultCode.ExceedDailyUsage)
            {
                // Occurs when there is a day's quota (regardless of recipient) that one person can send for a particular app.
            }
            else if (result.code == KGResultCode.ExceedMonthlyUsage)
            {
                // Occurs when one month exceeds a month's quota that a specific person can send to a particular app.
            }
            else if (result.code == KGResultCode.NotKakaoTalkUser)
            {
                // The logged-in user is not a "Kakao Talk" user. If you are not a KakaoTalk user with the account of a user who has just registered a cacao story.
            }
            else
            {
                // etc
            }
        });
    }
    else
    {
        // Image upload failed
    }
});

Android Example

// [TODO] Get my Kakao profile information from my Invite Friends list
KGKakaoProfile kakaoProfile;
  
if (kakaoProfile.isAllowedMessage == NO)
{
    // The user doesn't allow to receive Send a game message. Don't send the message.
    return;
}
// [TODO] Set game message template ID
String templateId;
  
// [TODO] Set image file
File file;
// Upload an image to get the image url
KGKakaoTalk.uploadGameImage(file, new KGResultCallback<String>() {
    @Override
    public void onResult(KGResult<String> result) {
        if (result.isSuccess()) {
            // The url of the uploaded image
            imageUrl = result.getContent();
        } else {
            // Image upload failed
        }
    }
});
  
// [TODO] Add required arguments to invitation message
Map<String, String> args = new LinkedHashMap<String, String>();
String nickname = ((KGKakaoProfile)KGLocalPlayer.getCurrentPlayer().getIdpProfile()).getNickname();
args.put("${sender_name}", nickname);
args.put("${first_image}", imageUrl); // Pass in the key specified in the message template
// Send a Kakaotalk game message
KGKakaoTalkMessage.sendNewGameMessage(kakaoProfile, templateId, args, new KGResultCallback<Boolean>() {
@Override
public void onResult(KGResult<Boolean> result) {
  if (result.isSuccess()) {
   // kakaoTalk game message sent successfully.
  } else {
   // KakaoTalk game message sent fail
   if (result.getCode() == KGResult.KGResultCode.MESSAGE_SETTING_DISABLE) {
    // If the recipient has opted-out of the message.
   } else if (result.getCode() == KGResult.KGResultCode.EXCEED_DAILY_USAGE) {
    // Occurs when there is a day's quota (regardless of recipient) that one person can send for a particular app.
   } else if (result.getCode() == KGResult.KGResultCode.EXCEED_MONTHLY_USAGE) {
    // Occurs when one month exceeds a month's quota that a specific person can send to a particular app.
   } else {
    // etc
   }
  }
}
});

iOS Example

#import <KakaoGame/KakaoGame.h>
// [TODO] Get my Kakao profile information from my Invite Friends list
KGKakaoProfile *kakaoProfile; // Kakaotalk profile(KGKakaoProfile Object)
  
if (kakaoProfile.isAllowedMessage == NO)
{
    // The user doesn't allow to receive Send a game message. Don't send the message.
    return;
}
// [TODO] Set image file
UIImage* file;
// Upload an image to get the image url
[KGKakaoTalk uploadGameImage:file completionHandler:^(NSError *error, NSString *imageUrl) {
    if (IS_SUCCESS(error) == YES)
    {
        // Pass in the key specified in the message template
        NSString* templateId = @"4101";
        NString* nickname = kakaoProfile.nickname;
        NSDictionary* argumentDic = @{@"${sender_name}":nickname, @"${first_image}":imageUrl};
   
        [KGKakaoTalkMessage sendNewGameMessageWithKakaoProfile:kakaoProfile templateId:templateId argumentDic:argumentDic completionHandler:^(NSError* error) {
            if (IS_SUCCESS(error) == YES)
            {
                // kakaoTalk game message sent successfully.
            }
            else
            {
                // 카카오톡 게임 메시지 보내기 실패
                if (error.code == KGErrorMessageSettingDisabled)
                {
                    // If the recipient has opted-out of the message.
                }
                else if (error.code == KGErrorExceedDailyUsage)
                {
                    // Occurs when there is a day's quota (regardless of recipient) that one person can send for a particular app.
                }
                else if (error.code == KGErrorExceedMonthlyUsage)
                {
                    // Occurs when one month exceeds a month's quota that a specific person can send to a particular app.
                }
                else if (error.code == KGErrorNotKakaoTalkUser)
                {
                    // The logged-in user is not a "Kakao Talk" user. If you are not a KakaoTalk user with the account of a user who has just registered a cacao story.
                }
                else
                {
                    // etc
                }
            }
        }];
    }
    else
    {
        // Image upload failed
    }
}];

  • 레이블 없음