This API is used to pass Access Token, APP ID, and gamePlayerId to the Huawei server to obtain playerId, openId, and unionId of a game player in a game of HarmonyOS 4 or earlier.
Use Access Token, APP ID, and gamePlayerId to query playerId, openId, and unionId of a game player in a game of HarmonyOS 4 or earlier from the Huawei server.
Protocol: HTTPS POST
Direction: Your server->Huawei game server
API URL: https://jos-open-api.cloud.huawei.com/gameservice/api/gbClientApi
Please use TLS 1.2 or a later version.
Data format:
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| method | Yes | String | This parameter must be set to external.hms.gs.player.transfer.convertId. |
| accessToken | Yes | String | Access token obtained by calling the Account Kit API for obtaining a user-level credential. |
| appId | Yes | String | App ID of the game for HarmonyOS 5.0 and later. For details about how to obtain it, please refer to Viewing App Information. |
| gamePlayerId | Yes | String | Player ID in the game of HarmonyOS 5.0 or later, which can be obtained through the unionLogin API. |
POST /gameservice/api/gbClientApi HTTP/1.1 Content-Type: application/x-www-form-urlencoded User-Agent: PostmanRuntime/7.24.0 Host: jos-open-api.cloud.huawei.com Accept-Encoding: gzip, deflate, br Connection: keep-alive Content-Length: 717 // The values of all request parameters must be URL-encoded before being concatenated. method=external.hms.gs.player.transfer.convertId&accessToken=******&appId=xxxxxxx&gamePlayerId=xxxxxxx
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| rtnCode | Yes | int | Result from the server. 0: The information is obtained successfully. -1: Failed to obtain the information. 2: The access token is invalid. 3001: Incorrect parameter. A request parameter is missing or the format is incorrect. 3101: The app ID is inconsistent with the client ID. |
| playerId | Yes | String | Game player ID provided by Game Service Kit by encapsulating the HUAWEI ID in HarmonyOS 4 or earlier. |
| openId | Yes | String | Player ID generated by encrypting the combination of a HUAWEI ID and the unique app ID in HarmonyOS 4 or earlier. |
| unionId | No | String | Player ID generated by encrypting the combination of a HUAWEI ID and a developer account ID in HarmonyOS 4 or earlier. |
| errMsg | No | String | Error message. |
HTTP/1.1 200 OK
Date: Tue, 19 May 2023 06:28:02 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Content-Encoding: gzip
Server: elb
{
"playerId": "13423***9864303",
"openId": "43JIOdok743***980sd9453",
"unionId": "MDFiaNicx***JHIicHAlnRD",
"rtnCode": 0
} Java
package okhttp.com.post;
import com.alibaba.fastjson.JSONObject;
import okhttp3.*;
import java.io.IOException;
public class ConvertIdTest {
private static Integer RETURN_CODE_SUCCEED = 0;
/**
* Used for local debugging.
*/
public static void main(String[] args) {
String method = "external.hms.gs.player.transfer.convertId"; // This parameter must be set to external.hms.gs.player.transfer.convertId.
String accessToken = "xxxxx"; // Use the access token in the Player object of the client.
String appId = "xxxx"; // App ID of the game for HarmonyOS 5.0 and later.
String gamePlayerId = "xxxxx"; // Player's gamePlayerId obtained from the Huawei server through the access token.
convertIdService(method, accessToken,appId, gamePlayerId);
}
private static void convertIdService(String method, String accessToken, String appId, String gamePlayerId) {
OkHttpClient client = new OkHttpClient().newBuilder().build();
RequestBody mFormBody = new FormBody.Builder().add("method", method)
.add("accessToken", accessToken)
.add("appId", appId)
.add("gamePlayerId", gamePlayerId)
.build();
Request request = new Request.Builder().url("https://jos-open-api.cloud.huawei.com/gameservice/api/gbClientApi")
.post(mFormBody)
.build();
try {
Response response = client.newCall(request).execute();
if (response.isSuccessful()) {
JSONObject object = JSONObject.parseObject(response.body().string());
if (RETURN_CODE_SUCCEED.equals(object.get("rtnCode"))) {
System.out.println("playerId: " + object.get("playerId"));
System.out.println("openId: " + object.get("openId"));
System.out.println("unionId: " + object.get("unionId"));
} else {
System.out.println("rtnCode: " + object.get("rtnCode"));
System.out.println("rtnMsg: " + object.get("errMsg"));
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
} C#
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
namespace cXdemo
{
class Program
{
static void Main(string[] args)
{
// This parameter must be set to external.hms.gs.player.transfer.convertId.
string method = "external.hms.gs.player.transfer.convertId";
// Use the access token in the Player object of the client.
string accessToken = "xxxxx";
// App ID of the game for HarmonyOS 5.0 and later.
string appId = "xxxx";
// Player's gamePlayerId obtained from the Huawei server through the access token.
string gamePlayerId = "xxxxx";
// Request API.
requestgameInfo(method, accessToken, appId, gamePlayerId);
}
static void requestgameInfo(string method, string accessToken, string appId, string gamePlayerId)
{
var requestUrl = "https://jos-open-api.cloud.huawei.com/gameservice/api/gbClientApi";
HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
request.Method = "post";
request.ContentType = "application/x-www-form-urlencoded";
StringBuilder data = new StringBuilder();
data.Append("method=" + HttpUtility.UrlEncode(method));
data.Append("&accessToken=" + HttpUtility.UrlEncode(accessToken));
data.Append("&appId=" + HttpUtility.UrlEncode(appId));
data.Append("&gamePlayerId=" + HttpUtility.UrlEncode(gamePlayerId));
byte[] byteData = Encoding.UTF8.GetBytes(data.ToString());
request.ContentLength = byteData.Length;
Stream postStream = request.GetRequestStream();
postStream.Write(byteData, 0, byteData.Length);
postStream.Close();
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string strJson = reader.ReadToEnd();
Console.WriteLine(strJson);
reader.Close();
response.Close();
}
}
} PHP
class convert_id
{
/**
* Obtain player information based on the access token.
*
* @param string $method Pass external.hms.gs.player.transfer.convertId.
* @param string $accessToken Use the access token in the Player object of the client.
* @param string $appId App ID of the game for HarmonyOS 5.0 and later.
* @param string $gamePlayerId Player's gamePlayerId obtained from the Huawei server through the access token.
*/
public function call_https(string $method, string $accessToken, string $appId, string $gamePlayerId): void
{
$data = array("method" => $method, "accessToken" => $accessToken, "appId" => $appId, "gamePlayerId" => $gamePlayerId);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://jos-open-api.cloud.huawei.com/gameservice/api/gbClientApi',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/x-www-form-urlencoded'
),
));
$response = curl_exec($curl);
if (curl_error($curl)) {
throw new Exception(curl_error($curl));
}
curl_close($curl);
$result = json_decode($response, true);
var_dump($result);
}
}
$convert_id = new convert_id();
$method = "external.hms.gs.player.transfer.convertId"; // This parameter must be set to external.hms.gs.player.transfer.convertId.
$accessToken = "xxxxx"; // Use the access token in the Player object of the client.
$appId = "xxxxx"; // App ID of the game for HarmonyOS 5.0 and later.
$gamePlayerId = "xxxxx"; // Player's gamePlayerId obtained from the Huawei server through the access token.
$convert_id->call_https($method, $accessToken, $appId, $gamePlayerId); Python
from typing import Any
import requests
import urllib.parse
class ConvertIdSolution:
def convert_id(self, method, accessToken, appId, gamePlayerId):
url = "https://jos-open-api.cloud.huawei.com/gameservice/api/gbClientApi"
params: dict[str, Any] = {
'method': method,
'accessToken': accessToken,
'appId': appId,
'gamePlayerId': gamePlayerId
}
encodedParams = urllib.parse.urlencode(params)
headers = {
'Content-Type': 'application/x-www-form-urlencoded'
}
response = requests.post(url, headers=headers, data=encodedParams)
print(response.text)
if __name__ == "__main__":
# This parameter must be set to external.hms.gs.player.transfer.convertId.
input_method = 'external.hms.gs.player.transfer.convertId'
# Use the access token in the Player object of the client.
input_accessToken = 'xxx'
# App ID of the game for HarmonyOS 5.0 and later.
input_appId = 'xxx'
# Player's gamePlayerId obtained from the Huawei server through the access token.
input_gamePlayerId = 'xxx'
function = ConvertIdSolution()
function.convert_id(input_method, input_accessToken, input_appId, input_gamePlayerId)