This function depends on the services provided by the Game SDK. The Game SDK may collect personal data of users. Inform users that their personal data will be collected and guide them to read the corresponding privacy policy before they use this function in your quick game.
Starting from version 1078, the API prefix has been changed from hbs to qg. The original prefix hbs is still supported.
| API | Description |
|---|---|
| Signs in to a game. | |
| Implements sign-in with game addiction prevention enabled. | |
| Stores a player's role information when the player selects the region and server to sign in to the game, or when the player level changes. If a game does not provide information such as the game level, role name, region and server, or game guild, this API does not need to be integrated. | |
| Stores a player's role information. | |
| Obtains the account ID. |
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| forceLogin | int | Yes | The value must be 1. The sign-in page will be displayed if a user does not sign in using a HUAWEI ID or the authentication fails. |
| appid | string | Yes | Unique ID allocated to a quick game created on HUAWEI Developers. For details, please refer to Obtaining the App ID. |
| success | function | No | Callback function triggered upon a successful API call. If code is 0, the API call is successful. For details, please refer to Parameters in the success callback function. NOTE: After the sign-in is successful, you are advised to call the API for verifying the sign-in signature to verify the sign-in result. |
| fail | function | No | Callback function triggered upon a failed API call, returning the failure cause. For details, please refer to Parameters in the fail callback function. |
| complete | function | No | If a function is passed, it will be called regardless of whether the API call succeeds or fails. |
| Parameter | Type | Description |
|---|---|---|
| playerId | String | Account ID. If the HUAWEI ID sign-in result does not need to be authenticated, a player can use playerId to sign in to the game after it is returned. |
| displayName | string | Nickname of a player. |
| playerLevel | integer | Player level. |
| isAuth | integer | When the value of isAuth is 1, the sign-in signature needs to be verified. |
| ts | string | Timestamp, which is used for sign-in signature verification. |
| gameAuthSign | string | Sign-in signature of a player, which is used by the app server to send a sign-in signature verification request to Huawei when calling the sign-in signature verification API. |
| Parameter | Type | Description |
|---|---|---|
| code | number | Returned status code. Code 0 indicates success. For details about other status codes, please refer to Status codes. The common result codes and their handling methods are as follows:
CAUTION: In addition to successful sign-in, you need to process the scenario where the player cancels sign-in (result code 7004 or 2012) when the sign-in page is displayed. You are advised to display the game page and provide the options for the player to sign in again or exit the game. |
| data | string | Message returned when an exception occurs. |
| Type | Description |
|---|---|
| Common result code | For details, please refer to common result codes. |
| Service result code | For details, please refer to game-related result codes and account-related result codes. |
qg.gameLogin({
forceLogin:1,
appid:"100453595",
success:function(data){
console.log("Game login success:" + data);
qg.savePlayerInfo({
appid:"100453595",
area:"cn",
rank:"1",
role:"a",
sociaty:"1",
success:function(data){console.log("Save player info success:" + data);},
fail:function(data,code){console.log("Save player info fail:" + data + ", code:" + code);}
});
},
fail:function(data,code){console.log("Game login fail:" + data + ", code:" + code);}
});Performs game addiction prevention on minors' playtime based on national laws and regulations. You can call this API for game sign-in to integrate the game addiction prevention capability.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| forceLogin | int | Yes | The value must be 1. The sign-in page will be displayed if a user does not sign in using a HUAWEI ID or the authentication fails. |
| appid | string | Yes | Unique ID allocated to a quick game created on HUAWEI Developers. For details, please refer to Obtaining the App ID. |
| success | function | No | Callback function triggered upon a successful API call. If code is 0, the API call is successful. For details, please refer to Parameters in the success callback function. |
| fail | function | No | Callback function triggered upon a failed API call, returning the failure cause. For details, please refer to Parameters in the fail callback function. |
| complete | function | No | If a function is passed, it will be called regardless of whether the API call succeeds or fails. |
| Parameter | Type | Description |
|---|---|---|
| playerId | string | Account ID. If the HUAWEI ID sign-in result does not need to be authenticated, a player can use playerId to sign in to the game after it is returned. |
| displayName | string | Nickname of a player. |
| playerLevel | integer | Player level. |
| ts | string | Timestamp, which is used for sign-in signature verification. |
| gameAuthSign | string | Authentication signature. |
| hiResImageUri | string | HD profile picture link. If this parameter is not set, the value is an empty string. |
| imageUri | string | Profile picture link. If this parameter is not set, the value is an empty string. |
| Parameter | Type | Description |
|---|---|---|
| code | number | Returned status code. For details, please refer to Status codes. The common result codes and their handling methods are as follows:
CAUTION: In addition to successful sign-in, you need to process the scenario where the player cancels sign-in (code 7004 or 2012) when the sign-in page is displayed. You are advised to display the game page and provide the options for the player to sign in again or exit the game. |
| data | string | Message returned when an exception occurs. |
qg.gameLoginWithReal({
forceLogin:1,
appid:"100**95",
success:function(data){
console.log("Game login success:" + data);
qg.savePlayerInfoWithReal({
rank:"1",
role:"a",
area:"cn",
sociaty:"1",
success:function(data){console.log("save player info with real success:" + data);},
fail:function(data,code){console.log("save player info with real fail:" + data + ", code:" + code);}
});
},
fail:function(data,code){console.log("game login with real fail:" + data + ", code:" + code);}
});Stores a player's role information when the player selects the region and server to sign in to the game, or when the player level changes. If a game does not provide information such as the game level, role name, region and server, or game guild, this API does not need to be integrated.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| appid | string | Yes | Unique ID allocated to a quick game created on HUAWEI Developers. For details, please refer to Obtaining the App ID. |
| rank | string | No | Player level in a game. |
| role | string | No | Role name created by a player in the game. Leave this parameter empty if no role name is set. |
| area | string | No | Region and server that a player selects when signing in to the game. Leave this parameter empty if no region or server is set. |
| sociaty | string | No | Guild to which a player belongs in the game. If the player does not join any guild, do not set this parameter. |
| success | function | No | Callback function triggered upon a successful API call, returning the retCode status code of the Int type. |
| fail | function | No | Callback function triggered upon a failed API call. |
| complete | function | No | If a function is passed, it will be called regardless of whether the API call succeeds or fails. |
qg.savePlayerInfo({
appid:"100453595",
area:"cn",
rank:"1",
role:"a",
sociaty:"1",
success:function(data){console.log("Save player info success:" + data);},
fail:function(data,code){console.log("Save player info fail:" + data + ", code:" + code);}
});Stores a player's role information when the player selects the region and server to sign in to the game, or when the player level changes. If a game does not provide information such as the game level, role name, region and server, or game guild, this API does not need to be integrated. This API will replace qg.savePlayerInfo.
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| rank | string | No | Player level in a game. |
| role | string | No | Role name created by a player in the game. Leave this parameter empty if no role name is set. |
| area | string | No | Region and server that a player selects when signing in to the game. Leave this parameter empty if no region or server is set. |
| sociaty | string | No | Guild to which a player belongs in the game. If the player does not join any guild, do not set this parameter. |
| success | function | No | Callback function triggered upon a successful API call. For details, please refer to Parameters in the success callback function. |
| fail | function | No | Callback function triggered upon a failed API call. For details, please refer to Parameters in the fail callback function. |
| complete | function | No | If a function is passed, it will be called regardless of whether the API call succeeds or fails. |
| Parameter | Type | Description |
|---|---|---|
| code | Integer | Returned status code. Code 0 indicates success. For details, please refer to Status codes. |
| Parameter | Type | Description |
|---|---|---|
| code | Integer | Returned status code. For details, please refer to Status codes. |
| data | String | Message returned when an exception occurs. |
qg.savePlayerInfoWithReal({
area: "cn-1", // Region and server of a player.
rank: "100", // Player level.
role: "A11", // Role name.
sociaty: "ss", // Guild.
success: function (res) {
console.log("save player info success");
that.getLabel.string = "Player information is successfully saved."+res.code;
},
fail: function (data, code) {
console.log("save player info fail:" + data + ", code:" + code);
that.getLabel.string = data + "," + code;
}
});| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| success | function | No | Callback function triggered upon a successful API call. If code is 0, the API call is successful. For details, please refer to Parameters in the success callback function. |
| fail | function | No | Callback function triggered upon a failed API call. For details, please refer to Parameters in the fail callback function. |
| complete | function | No | If a function is passed, it will be called regardless of whether the API call succeeds or fails. |
| Parameter | Type | Description |
|---|---|---|
| playerId | string | Player account ID, which is returned after a player signs in to the game using a HUAWEI ID. |
| Parameter | Type | Description |
|---|---|---|
| code | number | Returned status code. For details, please refer to Status codes. |
| data | string | Message returned when an exception occurs. |
qg.getCachePlayerId({
success: function (res) {
console.log("game getCachePlayerId: success"+res.playerId);
},
fail(data, code) {
console.log("on gameLoginWithReal fail: " + data + "," + code);
},
complete() {
console.log("on gameLoginWithReal: complete");
}
});