跳转到主要内容

查询玩家数据

用于加载其他玩家公开数据的 API。

URL 确认

此 API 使用 service-storage-api.playnanoo.com 域名。

API 信息

  • URL: https://service-storage-api.playnanoo.com/storage/v20221001/playerDataLoad
  • Method: PUT
  • 需要认证: 是
DeviceInfo 继承

此 API 的 Req 类继承自 DeviceInfo。DeviceInfo 的所有属性会自动包含。

请求参数

参数类型必填说明
player_uuidstring必填要查询的玩家 UUID
storage_keystring必填要加载的数据键

响应数据

Res 类

字段类型说明
PlayerIdstring玩家 ID
StorageKeystring已保存的数据键
StorageValuestring已保存的数据值

Unity C# 实现

BaseResponse 类

所有 API 响应的基类。

public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}

字段说明:

  • ErrorCode:错误代码
  • Message:错误信息
  • WithdrawalKey:账号处于注销等待状态时,用于恢复的密钥(仅注销等待中的账号提供)
  • BlockKey:账号被封禁时提供的密钥(仅被封禁的账号提供)

查询玩家数据类

using System;
using System.Collections;
using UnityEngine.Networking;

public class StoragePlayerLoad
{
static string path = "https://service-storage-api.playnanoo.com/storage/v20221001/playerDataLoad";

[Serializable]
public class Req : DeviceInfo
{
public string player_uuid; // 조회할 플레이어의 UUID
public string storage_key; // 불러올 데이터의 키

public IEnumerator Send(string player_uuid, string storage_key, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(player_uuid)) this.player_uuid = player_uuid;
if (!string.IsNullOrEmpty(storage_key)) this.storage_key = storage_key;

yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}

[Serializable]
public class Res : BaseResponse
{
public string PlayerId;
public string StorageKey;
public string StorageValue;
}
}

使用示例

public void LoadOtherPlayerData(string targetPlayerUUID)
{
StoragePlayerLoad.Req req = new StoragePlayerLoad.Req();

StartCoroutine(req.Send(
player_uuid: targetPlayerUUID,
storage_key: "public_profile",
onSuccess: res =>
{
Debug.Log("다른 플레이어 데이터 불러오기 성공");
Debug.Log($"플레이어 ID: {res.PlayerId}");
Debug.Log($"저장 키: {res.StorageKey}");

// JSON 역직렬화
var profile = JsonUtility.FromJson<PublicProfile>(res.StorageValue);
Debug.Log($"플레이어 이름: {profile.name}");
Debug.Log($"레벨: {profile.level}");
},
onError: error =>
{
Debug.LogError($"데이터 불러오기 실패: [{error.ErrorCode}] {error.Message}");
}
));
}

[Serializable]
public class PublicProfile
{
public string name;
public int level;
public string avatar;
}
公开数据

此 API 用于查询其他玩家的数据。请仅用于排名、好友信息等可公开共享的数据。

安全注意

请勿通过此方式存储敏感个人信息。只应存储即使公开也无妨的数据。