Skip to content

Login with SohaGame SDK

Overview

This guide explains how to integrate with Login for Android. Once authenticated users authorize your game, you can access their data including their display name and avatar.

Before you begin

You will need to Integrate the SohaGame SDK for Android into your game.

1. Login

Create the onLogin function to get the SDK calling the login function when logging in:

private void onLogin() {
    SohaSDK.getInstance().login(MainActivity.this, new LoginCallback() {
        @Override
        public void onSuccess(SohaLoginResult loginResult) {      
        //Please get the login result via SohaUser.getInstance().getSohaLoginResult()
            Log.d(TAG, "onSuccess: accessToken: " + SohaUser.getInstance().getSohaLoginResult().getAccessToken());
            Log.d(TAG, "onSuccess: userID: " + SohaUser.getInstance().getSohaLoginResult().getUserId());
        }

        @Override
        public void onError() {
            Log.d(TAG, "onError");
        }

        @Override
        public void onCancel() {
            Log.d(TAG, "onCancel");
            MainActivity.this.finish();
        }
    });
}
}

After a successful login will call the function onSuccess of onLogin

2. Logout

Create the onLogout function to call the logout function:

 private void onLogout() {
    SohaSDK.getInstance().logout(MainActivity.this);
}

Create LogoutCallback object to receive callback when logout :

  LogoutCallback logoutCallback = new LogoutCallback() {
    @Override
    public void onLogout() {
     onLogin();
     //write your code here
    }

It is required to handle ingame logout in this callback

3. Delete Account

First, you need a "Delete account" button in the ingame interface.

When the user clicks this button, call the following method:

 SohaSDK.getInstance().deleteAccount(this, new DeleteAccountCallback() {
                @Override
                public void onSuccess() {
                    //write your code here
                }

                @Override
                public void onFail(String message) {
                    Log.i(TAG, "DeleteAccountCallback: " + message);
                }
            });

After a successful delete will call the function onSuccess