Integrating New Capabilities of Game Service SDK 22.214.171.1242 Using Unity
Recently, I found that Unity had released a demo for Game Service SDK 126.96.36.1992. 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 188.8.131.520, whereas the latest version is 184.108.40.2062.
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.
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.
This API maps the getGamePlayer API of Game Service SDK 220.127.116.112. 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.
This API maps the getGamePlayer(boolean isRequirePlayerId) API of Game Service SDK 18.104.22.1682 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.
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.
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.
Compared with Game Service SDK 22.214.171.1240, 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.