[Huawei Developers] Mayism:
Background​

Recently, I found that Unity had released a demo for Game Service SDK 5.0.4.302. Let’s try this version.

Demo download from GitHub

SDK changes

I discovered that the last version of the Unity plugin for the Game Service SDK was 4.0.1.300, whereas the latest version is 5.0.4.302.

This version contains the following changes:

Added GetGamePlayer and GetGamePlayer(bool isRequirePlayerId) to obtain a player’s unique ID.

Added SetGameTrialProcess to listen to trial duration ending, which is used for preventing game addiction.

Added AccountAuthParamsHelper to obtain further information about a HUAWEI ID, including OpenID, UnionID, and the email address.

Added the OpenId, UnionId, AccessToken, and OpenIdSign parameters to the Player object.

Added AppPlayerInfo to save the information of the current player.

You can view change history details about the Game Service SDK on the official website.

Testing the APIs​

In this post, I just ran the Unity demo. If you’re not sure how to package and run a demo, check this post.

AccountAuthParamsHelper​

According to the C# source code, Unity supports request authorization in the following way:

AccountAuthParamsHelper authParamsHelper = new AccountAuthParamsHelper(); authParamsHelper.SetAuthorizationCode().SetAccessToken().SetIdToken().SetUid().SetId().SetEmail().CreateParams();

By using this code, you can request information including the authorization code, access token, ID token, UID, ID, and email address.

This part is also included in this document. You can complete configurations as required.

I tapped Login then login in the test app, which displayed the following page.

I selected Obtain your email address and tapped Authorise and log in. A welcome pop-up was displayed, containing the following information.

The OpenID, UnionID, access token, authorization code, and ID token could be found in the log information.

However, the email address I requested was not obtained. Why did this happen? I contacted Huawei technical support and found that no email address had been configured for the signed-in HUAWEI ID. So, I went to Settings > Account center > Account and security on my Huawei phone and discovered that there was indeed no email address.

After I configured an email address, the address could be obtained. The following figure shows the test result.

Huawei technical support also told me that UIDs currently cannot be obtained.

The latest plugin version allows you to obtain further information about a HUAWEI ID, including a player’s UnionID and OpenID.

GetGamePlayer​

This API maps the getGamePlayer API of Game Service SDK 5.0.4.302. According to official documentation, only displayName, openId, unionId, accessToken in the Player object have values. This is how I tested it.

I tapped Player then getGamePlayer in the test app, which displayed the following page.

The result was identical to that described in Huawei’s official documentation.

GetGamePlayer(bool isRequirePlayerId)​

This API maps the getGamePlayer(boolean isRequirePlayerId) API of Game Service SDK 5.0.4.302 and allows you to obtain the player ID and OpenID at the same time.

I tapped Player then getGamePlayer(isRequirePlayerId) in the test app, which displayed the following page.

This was also consistent with Huawei’s description.

Usage Description of GetGamePlayer and GetGamePlayer(bool isRequirePlayerId)​

For details about how to use the two APIs, please check this document.

setGameTrialProcess​

Official documentation states that this API is required for games released in the Chinese mainland in order to prevent game addiction. I skipped this step as my app will be released outside the Chinese mainland. In order to test this API you must submit a request to Huawei.

AppPlayerInfo​

This class is used when the savePlayerInfo API is called. I did not test this API as we saved our player information independently, meaning we did not use this API.

Test Summary​

Compared with Game Service SDK 4.0.1.300, this version of the Unity plugin has the following major changes:

Allowed you to set what information is obtainable from a HUAWEI ID, including OpenID, UnionID, and the email address.

Added the getGamePlayer API to allow games that have replaced player IDs with OpenIDs or UnionIDs to obtain player information. The getCurrentPlayer API is also available if you use the player ID as a unique user identifier.

Allowed games released in the Chinese mainland to call setGameTrialProcess for game trial support.