...
코드 블럭 | ||
---|---|---|
| ||
import com.kakaogame.KGTApplication; import com.kakaogame.KGTIdpProfile; import com.kakaogame.KGTPlayer; import com.kakaogame.KGTResult; KGTApplication.start(activity, null, result -> { if (result.isSuccess()) { // If the start is successful // Check if auto-login is enabled boolean isLoggedIn = KGTPlayer.isLoggedIn(); if (isLoggedIn) { // The ID of the current Player's ID issued by the platform String playerId = KGTPlayer.getCurrentPlayer().getPlayerId(); // Platform access token (ZAT) String accessToken = KGTPlayer.getCurrentPlayer().getAccessToken(); // Retrieve the current IDP authentication information KGTIdpProfile idpProfile = KGTPlayer.getCurrentPlayer().getIdpProfile(); // [TODO] Move to the game screen. } else { // [TODO] If auto-login is not enabled, move to the login screen. } } else { // If the start fails - since initialization failed, you should retry the start or exitclose the app. int resultCode = result.getCode(); if (resultCode == KGTResult.KGTResultCode.NETWORK_FAILURE || resultCode == KGTResult.KGTResultCode.SERVER_TIMEOUT || resultCode == KGTResult.KGTResultCode.SERVER_CONNECTION_FAILED) { // [TODO] If a network error occurs, inform the user that the start failed due to a network issue and retry. } else { // [TODO] If anotherother errorerrors occursoccur, provide an error messagenotification and promptrequest toa retry of the start process. - If the problemissue persists, check the error code and logs to determine the cause. } } }); |
...
코드 블럭 | ||
---|---|---|
| ||
import com.kakaogame.KGTApplication; import com.kakaogame.KGTResult; KGTApplication.resume(activity, result -> { if (result.isSuccess()) { // [TODO] If resume is successful, resume the game screen. } else { // [TODO] If resume fails, movenavigate to the login screen if it'sit’s an authentication failure,; and otherwise, show an error popup and check whetherif the user wants to retry. if (result.getCode() == KGTResult.KGTResultCode.AUTH_FAILURE || result.getCode() == KGTResult.KGTResultCode.IDP_AUTH_FAILURE) { // [TODO] In case of authentication failure, move to the start screen and perform the new login flow again. } else { // [TODO] ForIf other errors occur, showprovide an error messagenotification and request a retry of the resumestart process. - If the issue persists, closecheck the app. } } }error code and logs to determine the cause. } } }); |
Adding a New Intent Receive Setting
...
코드 블럭 | ||
---|---|---|
| ||
import com.kakaogame.KGTApplication; import com.kakaogame.KGTIdpProfile; import com.kakaogame.KGTPlayer; import com.kakaogame.KGTResult; // Set the IdpCode for the login KGTIdpProfile.KGTIdpCode code = KGTIdpCode.Kakao; // Log in with a specific IDP KGTPlayer.login(activity, code, result -> { if (result.isSuccess()) { // IDP login and platform login succeeded // The current Player's ID issued by the platform String playerId = KGTPlayer.getCurrentPlayer().getPlayerId(); // Platform access token String accessToken = KGTPlayer.getAccessToken(); // Retrieve the current IDP authentication information KGTIdpProfile idpProfile = KGTPlayer.getCurrentPlayer().getIdpProfile(); // [TODO] Since login was successful, proceed to the game screen. } else { // IDP login or platform login failed // [TODO] In case ofIf login failurefails, inform the user and allowprompt them ato retry. if (result.getCode() == KGTResult.KGTResultCode.NETWORK_FAILURE || result.getCode() == KGTResult.KGTResultCode.SERVER_TIMEOUT || result.getCode() == KGTResult.KGTResultCode.SERVER_CONNECTION_FAILED) { // [TODO] If a network error occurs, prompt the user to retry thelogging loginin. } else if (result.getCode() == KGTResult.KGTResultCode.USER_CANCELED) { // [TODO] IfSince the user canceled during the login process, keep the login screen should be activemaintained. } else if (result.getCode() == KGTResult.KGTResultCode.BLOCKED_BY_POLICY) { // [TODO] The login was attempted from a blocked country code or IP range. Handle accordingly. } else { // [TODO] ForIf any other errors occur, displayprovide an error messagenotification and prompt the user to retry logging loginin. - Check It is necessary to check the error code and logs to identifydetermine the cause. } } }); |
Logout
...
발췌문 삽입 | ||||||||
---|---|---|---|---|---|---|---|---|
|
...
코드 블럭 | ||
---|---|---|
| ||
import com.kakaogame.KGTKakaoTalk; // Display the KakaoTalkview game to set KakaoTalk game message reception setting viewpreferences KGTKakaoTalk.showSetting(activity, result -> { if (result.isSuccess()) { // Successfully set the KakaoTalk game message reception settings boolean allowMessage = result.getContent(); // Whether message reception is allowed as per the settings } else if (result.getCode() == KGTResult.KGTResultCode.NOT_KAKAOTALK_USER) { // The logged-in user is not a 'KakaoTalk' user. This occurs ifwhen the accountuser is only registered with KakaoStory and not with KakaoTalk not a KakaoTalk user, such as in the case of a user who is only registered for KakaoStory. } else { // Failed to set the KakaoTalk game message reception settings } }); |
Retrieve KakaoTalk Profile
...
코드 블럭 | ||
---|---|---|
| ||
import com.kakaogame.KGTKakaoTalk; import com.kakaogame.KGTKakaoTalkProfile; // Retrieve KakaoTalk profile KGTKakaoTalk.talkProfile(result -> { if (result.isSuccess()) { // Successfully retrieved KakaoTalk profile talkProfile = result.getContent(); // The KakaoTalk profile information of the logged-in user } else if (result.getCode() == KGTResult.KGTResultCode.NOT_KAKAOTALK_USER) { // The logged-in user is not a 'KakaoTalk' user. This occurs ifwhen the accountuser is only registered with KakaoStory and not with KakaoTalk not a KakaoTalk user, such as in the case of a user who is only registered for KakaoStory. } else { // Failed to retrieve KakaoTalk profile } }); |
...
코드 블럭 | ||
---|---|---|
| ||
import com.kakaogame.KGTKakaoTalk; import com.kakaogame.KGTKakaoFriendProfile; // Retrieve the list of game friends KGTKakaoTalk.friends(result -> { if (result.isSuccess()) { // Successfully retrieved the KakaoTalk game friends list. List<KGTPlayer> friendList = result.getContent(); // Game friends list for (KGTPlayer player : friendList) { KGTKakaoFriendProfile kakaoProfile = (KGTKakaoFriendProfile)player.getIdpProfile(); } } else if (result.getCode() == KGTResult.KGTResultCode.NOT_KAKAOTALK_USER) { // The logged-in user is not a 'KakaoTalk' user. This occurs ifwhen the accountuser is only registered with KakaoStory and not with KakaoTalk not a KakaoTalk user, such as in the case of a user who is only registered for KakaoStory. } else { // Failed to retrieve the KakaoTalk game friends list } }); |
...
코드 블럭 | ||
---|---|---|
| ||
import com.kakaogame.KGTKakaoFriendProfile; import com.kakaogame.KGTKakaoTalk; import com.kakaogame.KGTKakaoTalkProfile; // Friend object retrieved through the friends API KGTKakaoFriendProfile kakaoProfile; // Kakao profile (KGTKakaoFriendProfile object) // [TODO] Set the Template IDId String templateId = ""; // [TODO] Set the arguments for the message template Map<String, String> args = new LinkedHashMap<>(); if (talkProfile != null) { args.put("${nickname}", talkProfile.getNickname()); } args.put("rog_link", "test=100&hello=20111"); args.put("bruce2", "test=100&hello=20111"); // Send a KakaoTalk game message KGTKakaoTalk.sendGameMessage(kakaoProfile, templateId, args, result -> { if (result.isSuccess()) { // Successfully sent a KakaoTalk chat message } else { if (result.getCode() == KGTResult.KGTResultCode.MESSAGE_SETTING_DISABLE) { // The recipient has set message reception to disabled } else if (result.getCode() == KGTResult.KGTResultCode.EXCEED_DAILY_USAGE) { // Occurs Thewhen the daily quota for sending messages fromto a singlespecific app has been exceeded (regardless of the recipient) is exceeded. } else if (result.getCode() == KGTResult.KGTResultCode.EXCEED_MONTHLY_USAGE) { // Occurs Thewhen the monthly quota for sending messages to a specific person fromfor a singlespecific app hasis been exceeded. } else { // Failed to send the KakaoTalk chat message } } }); |
...
코드 블럭 | ||
---|---|---|
| ||
import com.kakaogame.KGTKakaoTalk; import com.kakaogame.KGTKakaoTalkProfile; import com.kakaogame.KGTKakaoUser; // [TODO] Set whether to display as a popup window boolean isSingle = true; // [TODO] Set whether to display as a popup window boolean isPopup = true; // [TODO] Set the template Id String templateId = ""; // [TODO] Set the parameters for the message template Map<String, String> args = new LinkedHashMap<>(); if (talkProfile != null) { args.put("${nickname}", talkProfile.getNickname()); } KGTKakaoTalk.sendInviteMessage(activity, isSingle, isPopUp, templateId, args, result -> { if (result.isSuccess()) { // Successfully sent KakaoTalk invite message for (KGTKakaoUser kakaoUser : result.getContent()) { // Check the list of users who received the invite message } } else { // Failed to send to all users (need to return a common cause) if (result.getCode() == KGTResult.KGTResultCode.MESSAGE_SETTING_DISABLE) { // The recipient has set message reception to disabled } else if (result.getCode() == KGTResult.KGTResultCode.EXCEED_DAILY_USAGE) { // Occurs when a user exceeds the daily quota for sending messages fromto a specific app (regardless of the recipient) is exceeded. } else if (result.getCode() == KGTResult.KGTResultCode.EXCEED_MONTHLY_USAGE) { // Occurs when a user exceeds the monthly quota for sending messages to a specific person fromfor a specific app is exceeded. } else { // Failed to send KakaoTalk invite message } } }); |
...
코드 블럭 | ||
---|---|---|
| ||
import com.kakaogame.KGTKakaoTalk; // [TODO] Set the channel Id int channelId = 0; KGTKakaoTalk.addChannel(plusFriendId, result -> { if (result.isSuccess()) { // Successfully added the channel } else if (result.getCode() == KGTResult.KGTResultCode.NOT_KAKAOTALK_USER) { // The logged-in user is not a 'KakaoTalk' user. This occurs when the user is not a KakaoTalk user, such as in the account case of a user who is only registered withfor KakaoStory and not KakaoTalk. } else { // Failed to add the channel } }); |
...