Skip to main content

Android

This article guides you through setting up VNG as an identity provider, enabling your Android game to access Player Network authentication services.

Prerequisites

1. Set up the VNG app

Contact VNG to apply the following app configuration parameters.

  1. VNG GameID
  2. appsFlyerDevKey (if you have applied for AppsFlyer from VNG)
  1. Create an account for Player Network Console.
  2. Create a new project for your game, or join an existing one.
  3. Download the SDK.
  4. Integrate the SDK.
  5. Add VNG as an authentication method for your project on Player Network Console.

Step 1: Configure the SDK

  1. Set the following values in the GTSDK.json file under Assets/Plugins/Android/INTLVNG.androidlib/assets.

    {
    "gameID": "VNG_GameId",
    "appsFlyerDevKey": "VNG_appsFlyerDevKey",
    "gameVersion": "1.0.0",
    "modules": [
    {
    "name": "GGID",
    "clientId": "{VNG_GG_APP_ID}",
    "clientToken": "{VNG_GG_CLIENT_TOKEN}"
    }
    ]
    }
  2. Place GTSDK.json in the assets directory.
    Do not change the location and file name of GTSDK.json as the VNG SDK internally reads the content named GTSDK.json in the specified directory.

  3. Define manifestPlaceholders in the gradle file by replacing {INTL_VNG_GG_APP_ID} and {INTL_VNG_GG_CLIENT_TOKEN} with the VNG App ID and Client Token.

    mainTemplate.gradle
    android {
    defaultConfig {
    manifestPlaceholders = [
    'VNG_GG_APP_ID' : '{INTL_VNG_GG_APP_ID}',
    'VNG_GG_CLIENT_TOKEN' : '{INTL_VNG_GG_CLIENT_TOKEN}',
    ]
    }
    }
  4. [Optional] If minSdkVersion does not match, add the following code to the project's manifest.

    <uses-sdk tools:overrideLibrary="vng.com.gtsdk,vng.com.gtsdk.gtloginkit,vng.com.gtstk.gtzingkit,vng.com.gtsdk.gtextension,vn.com.vng.gg.ggsigninsdk,com.intlgame.vng" />
  5. [Optional] For Unity, refer to the mainTemplate.gradle provided in SDK, and add the corresponding field such as androidDependenciesAdapter, intlChannelDespendencies, androidXDependencies, commonVersions, thirdChannel.

    /*Intlvng_start*/
    Implementation rootproject.extRoidDePendenCiesadapter.appCompat
    Implementation rootproject.Ext.intlChanneneLDESPENDENCIES.ROFIT2GSON
    Implementation rootproject.Ext.intlChanneldespendenCies.FirebaseMessage
    Implementation rootproject.Ext.intlChanneldespendenCies.googlegcm
    Implementation rootproject.Ext.intlChannelDespendenCies.appsFlyer
    Implementation rootproject.Ext.intlChanneldespendenCies.installreferrerrrrrr
    Implementation rootproject.ext.androidXDependenCies.lifecycle
    /*Intlvng_end*/

Step 2: Add VNG login

  1. Add an observer to handle authentication callbacks.

    // Add callbacks
    public void AddAuthObserver()
    {
    INTLAPI.AddAuthResultObserver(OnAuthResultEvent);
    }

    // Remove callbacks
    public void RemoveAuthObserver()
    {
    INTLAPI.RemoveAuthResultObserver(OnAuthResultEvent);
    }

    // Process the INTLAuthResult callback
    public void OnAuthResultEvent(INTLAuthResult ret)
    {
    Debug.Log($"MethodID: {ret.MethodId}");

    string methodTag = "";
    if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_LOGIN)
    {
    methodTag = "Login";
    }
    else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_BIND)
    {
    methodTag = "Bind";
    }
    else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_AUTOLOGIN)
    {
    methodTag = "AutoLogin";
    }
    else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_QUERY_USER_INFO)
    {
    methodTag = "QueryUserInfo";
    }
    else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_GET_AUTH_RESULT)
    {
    methodTag = "GetAuthResult";
    }
    }
  2. Call the AutoLogin method.

    When a user has logged in before, the game backend can achieve automatic login by calling the auto-login interface. If the token is still effective within the validity period, login will be successful. If the token fails, an error prompt will appear, and the game needs to call the manual login interface to log in again.

    INTLAPI.AutoLogin();
  3. Call the Login method to ask for user input if auto-login fails.

    INTLAPI.Login(INTLChannel.VNG, "", "");

    After calling the API, the following window will appear:

    Image: Login Interface

    The parameters returned after logging in is:

    {
    "extraJson":"
    {
    }",
    "methodID":102,
    "retCode":0,
    "retMsg":"Success",
    "ret":0,
    "msg":"success",
    "bind_list":"",
    "birthday":"",
    "channel":"VNG",
    "channel_info":"
    {
    \"email\":\"null\",
    \"expire_ts\":1660373805,
    \"session_id\":\"MTSVN_23195b047d99a2b164296ab85cb956fa76e631657781803922\",
    \"social_id\":\"646605735\",
    \"update_in\":1657781803520,
    \"user_id\":\"2213855217680687104\",
    \"user_name\":\"mtschecking02\"
    }",
    "channelid":38,
    "confirm_code":"",
    "confirm_code_expireTime":0,
    "del_account_status":-10,
    "first_login":0,
    "gender":0,
    "legal_doc":"",
    "openid":"824624458301451",
    "pf":"unknown_uk-00000000-android-00000000-uk-MTSVN-824624458301451",
    "pf_key":"4c5a49c1407cfe7ab09fba44e343810e",
    "picture_url":"",
    "need_name_auth":false,
    "token":"bd13b7147297a5c58c27f414ea21ae00f67f2208",
    "token_expire_time":1660373805,
    "user_name":"mtschecking02"
    }
    caution

    The user_id is the only identification of the current user, use it on the customer service interface.

  4. Sync client authentication state with the game's backend and wait for the final authentication result.

Logout

Users can log out of the current login channel. The game backend need to call the interface Logout and pass the relevant parameters.

INTLAPI.Logout();

Step 3: Test the login function

Search for the keyword "AuthResult" in the Player Network SDK logs to verify if the correct channel name and OpenID are returned. If they are, it indicates a successful configuration and the login function has been added successfully.

Other Functions

Link

Users can link VNG and channels that have been logged in, such as operations such as synchronous data. Users can call the Bind interface and pass the relevant parameters.

Taking Facebook as an example:

INTLAPI.Bind(INTLChannel.Facebook);

For more information, see the Bind API for Unity SDK or Unreal Engine SDK.

VNG Customer Service

VNG provides customer service, and supports it through extend in Player Network SDK. The callback is:

string json="{\"user_id\":\"xxx\",\"login_type\":\"ZM\"}";;
INTLAPI.ExtendInvoke(INTLChannel.VNG, "showCustomerSupport",json);

The content in JSON includes the following fields, that users can fill in as needed:

NameFieldDescriptionRemarks
user_idstringLog in the user ID Required
login_typestringUser login type Required (zing corresponds: "zm")
role_namestringCharacter NameOptional
levelstringCharacter levelOptional
guildstringGroups of character belongingOptional
contentstringIs the character IDOptional
server_idstringServer IDOptional

The corresponding value of login_type is:

Login channelLogintype
GuestGU
FacebookFB
GoogleGG
ZingIDZM
LINELINE
AppleIDAP
EmailEM
ZaloZL
VNG IDCM

The following interface will appear after calling:

Image: Customer Service Service

The following parameter will be returned when the page is closed:

{
"extraJson":"
{

}",
"methodID":1301,
"retCode":0,
"retMsg":"Success",
"ret":0,
"msg":"",
"channel":"VNG",
"extend_method_name":"showCustomerSupport"
}