5.1. Connect Account Example

5.1. Connect Account Example

 


5.1.1. Connect Account Example

  • When the Connect Account API which uses the basic account connection UI is called, a window appears as below asking you to decide which IDP you will use.

     

  • In the event that the developer wants to implement the account connection UI (i.e. the developer does not want to use the basic account connection UI), connect account API by IDP is provided. In this case, a connect account button for each IDP should be placed in the account connection screen, and when each button is clicked, the connect account API for each IDP should be called.

5.1.2. Connect accounts using the basic account connection UI

The following is an example of connect account using the basic account connection UI.

  • Connect to other IDP accounts is available only after the guest, SIWA(in Korea, iPhone only) has been authenticated. Otherwise, you have to deactive the account connection UI.

  • If connect account is successful, the player ID is maintained.

Unity

using Kakaogame.SDK;   KGSession.Connect(     (result) => {         if (result.isSuccess) {             // Account connection successful             // The player ID is not changed.         }         else if (result.code == KGResultCode.NotAuthorized) {             // If currently not authenticated         }         else if (result.code == KGResultCode.InvalidState) {             // If currently authenticated IDP is not guest, or SIWA(in Korea, iPhone only)         }         else if (result.code == KGResultCode.AlreadyUsedIdpAccount) {             // If trying to convert to an already used IDP account         }         else {             // Other errors         }     });

Android

// Connect Account KGSession.connect(activity, new KGResultCallback<Void>() {     @Override     public void onResult(KGResult<Void> result) {           if (result.isSuccess()) {             // Account connection successful             // The player ID is not changed.         } else {             // Account connection failed               if (result.getCode() == KGResult.KGResultCode.INVALID_PARAMETER) {                 // If activity is null             } else if (result.getCode() == KGResult.KGResultCode.NOT_AUTHORIZED) {                 // If currently not authenticated             } else if (result.getCode() == KGResult.KGResultCode.INVALID_STATE) {                 // If currently authenticated IDP is not guest.             } else if (result.getCode() == KGResult.KGResultCode.ALREADY_USED_IDP_ACCOUNT) {                 // If trying to convert to an already used IDP account             } else {                 // Other errors             }         }     } });

iOS

#import <KakaoGame/KakaoGame.h>   // Connect Account [KGSession connectWithCompletionHandler:^(NSError *error) {     if (IS_SUCCESS(error) == YES)     {           // Account connection successful         // The player ID is not changed.     }     else     {         // Account connection failed           if (error.code == KGErrorNotAuthorized)         {             // If currently not authenticated         }         else if (error.code == KGErrorInvalidState)         {             // If currently authenticated IDP is not guest, or SIWA(in Korea only)         }         else if (error.code == KGErrorAlreadyUsedIdpAccount)         {               // If trying to convert to an already used IDP account         }         else         {             // Other errors         }     } }];

Unreal

#include "KakaoGame.h"    FKGSession::Connect(FKGResultDelegate::CreateLambda([=](FKGResult result) {   if (result.IsSuccess())   {     // Account connection successful     // The player ID is not changed.   }   else if (result.GetCode() == FKGResultCode::NotAuthorized)   {     // If currently not authenticated   }   else if (result.GetCode() == FKGResultCode::InvalidState)   {     // If currently authenticated IDP is not guest, or SIWA(in Korea, iPhone only)   }   else if (result.GetCode() == FKGResultCode::AlreadyUsedIDPAccount)   {     // If trying to convert to an already used IDP account   }   else   {     // Other errors   } }));

5.1.3. Connect accounts not using the basic account connection UI

The following is an example of connect account not using the basic account connection UI.

  • Connect to other IDP accounts is available only after the guest, SIWA(in Korea, iPhone only) has been authenticated. Otherwise, you have to deactive the account connection UI.

  • If connect account is successful, the player ID is maintained.

Unity

using Kakaogame.SDK;   KGIdpCode idpCode = KGIdpCode.Kakao; // IDP to be used for account connection   // Connect accounts not using the basic account connection UI KGSessionForCustomUI.Connect(     idpCode,     (result) => {         if (result.isSuccess) {             // Account connection successful             // The player ID is not changed.         }         else if (result.code == KGResultCode.NotAuthorized) {             // If currently not authenticated         }         else if (result.code == KGResultCode.InvalidState) {             // If currently authenticated IDP is not guest, or SIWA(in Korea, iPhone only)         }         else if (result.code == KGResultCode.AlreadyUsedIdpAccount) {             // If trying to convert to an already used IDP account         }         else {             // Other errors         }     });

Android

// Connect accounts not using the basic account connection UI KGIdpProfile.KGIdpCode idpCode; // IDP to be used for account connection   KGSessionForCustomUI.connect(activity, idpCode, new KGResultCallback<Void>() {     @Override     public void onResult(KGResult<Void> result) {           if (result.isSuccess()) {             // Account connection successful             // The player ID is not changed.         } else {             // Account connection failed               if (result.getCode() == KGResult.KGResultCode.INVALID_PARAMETER) {                 // If activity is null             } else if (result.getCode() == KGResult.KGResultCode.NOT_AUTHORIZED) {                 // If currently not authenticated             } else if (result.getCode() == KGResult.KGResultCode.INVALID_STATE) {                 // If currently authenticated IDP is not guest.             } else if (result.getCode() == KGResult.KGResultCode.ALREADY_USED_IDP_ACCOUNT) {                 // If trying to convert to an already used IDP account             } else {                 // Other errors             }         }     } });

iOS

#import <KakaoGame/KakaoGame.h>   // Connect accounts not using the basic account connection UI KGIdpCode idpCode = KGIdpCodeKakao; // IDP to be used for account connection   [KGSessionForCustomUI connectWithIdpCode:idpCode completionHandler:^(NSError *error) {     if (IS_SUCCESS(error) == YES)     {           // Account connection successful         // The player ID is not changed.     }     else     {         // Account connection failed           if (error.code == KGErrorNotAuthorized)         {             // If currently not authenticated         }         else if (error.code == KGErrorInvalidState)         {             // If currently authenticated IDP is not guest, or SIWA(in Korea only)         }         else if (error.code == KGErrorAlreadyUsedIdpAccount)         {               // If trying to convert to an already used IDP account         }         else         {             // Other errors         }     } }];

Windows Sync

#include "KakaoGameLib.h"   KakaoGame::API::KGSessionForCustomUI kgSessionForCustomUI; KakaoGame::Data::KGResult result;    // IDP to be used for account connection KakaoGame::Data::KGIdpCode idpCode;   // Connect accounts not using the basic account connection UI kgSessionForCustomUI.connect(idpCode, result); if (result.isSuccess()) {     // Account connection successful     // The player ID is not changed. } else if (KakaoGame::Data::KGResultCode::NotAuthorized == result.code) {     // If currently not authenticated } else if (KakaoGame::Data::KGResultCode::NotSupported == result.code) {     // Unable to connect idp } else if (KakaoGame::Data::KGResultCode::AlreadyUsedIDPAccount == result.code) {     // If trying to convert to an already used IDP account } else {     // Other errors }

Windows Async

#include "KakaoGameLib.h"   KakaoGame::API::KGSessionForCustomUI kgSessionForCustomUI; KakaoGame::Data::KGResult result;   // IDP to be used for account connection KakaoGame::Data::KGIdpCode idpCode;   // Connect accounts not using the basic account connection UI kgSessionForCustomUI.connect(idpCode, [this](KakaoGame::Data::KGResult result) {     if (result.isSuccess()) {         // Account connection successful         // The player ID is not changed.     }     else if (KakaoGame::Data::KGResultCode::NotAuthorized == result.code) {         // If currently not authenticated     }     else if (KakaoGame::Data::KGResultCode::NotSupported == result.code) {         // Unable to connect idp     }     else if (KakaoGame::Data::KGResultCode::AlreadyUsedIDPAccount == result.code) {         // If trying to convert to an already used IDP account     }     else {         // Other errors     } }, reinterpret_cast<HWND>(GEngine->GameViewport->GetWindow()->GetNativeWindow()->GetOSWindowHandle());

Unreal

#include "KakaoGame.h"    // Connect accounts not using the basic account connection UI EKGIdpCode idpCode = EKGIdpCode::Kakao; // IDP to be used for account connection    FKGSessionForCustomUI::Connect(idpCode, FKGResultDelegate::CreateLambda([=](FKGResult result) {   if (result.IsSuccess())   {     // Account connection successful     // The player ID is not changed.   }   else if (result.GetCode() == FKGResultCode::NotAuthorized)   {     // If currently not authenticated   }   else if (result.GetCode() == FKGResultCode::InvalidState)   {     // If currently authenticated IDP is not guest, or SIWA(in Korea only)   }   else if (result.GetCode() == FKGResultCode::AlreadyUsedIDPAccount)   {     // If trying to convert to an already used IDP account   }   else   {     // Other errors   } }));

5.1.4. Kacao 'app-to-web' login without the default account connection UI (3.8.0+)

This is an example of implementing a Kacao 'app-to-web' login when connecting accounts that do not use the default account connection UI.

  • Connect to other IDP accounts is available only after the guest, SIWA(in Korea, iPhone only) has been authenticated. Otherwise, you have to deactive the account connection UI.

  • If connect account is successful, the player ID is maintained.

  • In the version below 3.8.0, only the 'app-to-app' authentication was supported when KakaoTalk app was installed by default. You can use the following APIs to allow users to select 'Kakao app' or 'web' authentication to log in, or to perform an 'app-to-web' authentication.

Unity

using Kakaogame.SDK;   // Users select app or web authentication and sign in KGKakaoAuthType authType = KGKakaoAuthType.KakaoAllType; // Login KakaoWeb // KGKakaoAuthType authType = KGKakaoAuthType.KakaoWeb;     // Connect accounts that do not use the default account connection UI KGSessionForCustomUI.ConnectKakao(     authType,     (result) => {         if (result.isSuccess) {             // Account connection successful             // The player ID is not changed.         }         else if (result.code == KGResultCode.NotAuthorized) {             // If currently not authenticated         }         else if (result.code == KGResultCode.InvalidState) {             // If currently authenticated IDP is not guest, or SIWA(in Korea, iPhone only)         }         else if (result.code == KGResultCode.AlreadyUsedIDPAccount) {             // If trying to convert to an already used IDP account         }         else {             // Other errors         }     });

Android

// Connect accounts not using the basic account connection UI    // User selects 'app' or 'web' authentication and logs in KGKakaoAuthType authType = KGKakaoAuthType.KakaoAllType; // app to web login only //// KGKakaoAuthType authType = KGKakaoAuthType.KakaoWeb;   KGSessionForCustomUI.connectKakao(getActivity(), authType, new KGResultCallback<Void>() {     @Override     public void onResult(KGResult<Void> result) {         if (result.isSuccess()) {             // Account connection successful             // The player ID is not changed.         } else {             // Account connection failed               if (result.getCode() == KGResult.KGResultCode.INVALID_PARAMETER) {                 // If activity is null             } else if (result.getCode() == KGResult.KGResultCode.NOT_AUTHORIZED) {                 // If currently not authenticated             } else if (result.getCode() == KGResult.KGResultCode.INVALID_STATE) {                 // If currently authenticated IDP is not guest.             } else if (result.getCode() == KGResult.KGResultCode.ALREADY_USED_IDP_ACCOUNT) {                 // If trying to convert to an already used IDP account             } else {                 // Other errors             }         }     } });

iOS

#import <KakaoGame/KakaoGame.h>      // Users select app or web authentication and sign in KGKakaoAuthType authType = KGKakaoAuthTypeKakaoAllType; // Login KakaoWeb //// KGKakaoAuthType authType = KGKakaoAuthTypeKakaoWeb;     // Connect accounts that do not use the default account connection UI [KGSessionForCustomUI connectKakaoWithKakaoAuthType:authType completionHandler:^(NSError *error) {      if (IS_SUCCESS(error) == YES) {         // Account connection successful         // The player ID is not changed.     }     else {         // Account connection failed         if (error.code == KGErrorNotAuthorized) {             // If currently not authenticated         }         else if (error.code == KGErrorInvalidState) {             // If currently authenticated IDP is not guest, or SIWA(in Korea only)         }         else if (error.code == KGErrorAlreadyUsedIdpAccount) {             // If trying to convert to an already used IDP account         }         else {             // Other errors         }     } }];

Unreal

#include "KakaoGame.h"    // Users select app or web authentication and sign in EKGKakaoAuthType authType = EKGKakaoAuthType::KakaoAllType;   // Login KakaoWeb // EKGKakaoAuthType authType = EKGKakaoAuthType.KakaoWeb;   FKGSessionForCustomUI::ConnectKakao(authType, FKGResultDelegate::CreateLambda([=](FKGResult result) {   if (result.IsSuccess())   {     // Account connection successful     // The player ID is not changed.   }   else if (result.GetCode() == FKGResultCode::NotAuthorized)   {     // If currently not authenticated   }   else if (result.GetCode() == FKGResultCode::InvalidState)   {     // If currently authenticated IDP is not guest, or SIWA(in Korea only)   }   else if (result.GetCode() == FKGResultCode::AlreadyUsedIDPAccount)   {     // If trying to convert to an already used IDP account   }   else   {     // Other errors   } }));