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

Authenticate user

There are 2 ways for you to authenticate users

  • Service To Service (S2S) Authentication (Recommend).
    After obtaining the access token, the game will send it to the game server, then the game server will push a request to the SohaGame server to verify the account information being logged !!! note "API documentation for S2S Authentication can be see here"

  • Use userId for authentication.

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