본문으로 건너뛰기

데이터 조회

저장된 게임 데이터를 불러오는 API입니다.

URL 확인

이 API는 service-storage-api.playnanoo.com 도메인을 사용합니다.

API 정보

  • URL: https://service-storage-api.playnanoo.com/storage/v20221001/load
  • Method: PUT
  • 인증 필요: 예
DeviceInfo 상속

이 API의 Req 클래스는 DeviceInfo를 상속받습니다. DeviceInfo의 모든 속성이 자동으로 포함됩니다.

요청 파라미터

파라미터타입필수설명
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 StorageLoad
{
static string path = "https://service-storage-api.playnanoo.com/storage/v20221001/load";

[Serializable]
public class Req : DeviceInfo
{
public string storage_key; // 불러올 데이터의 키

public IEnumerator Send(string storage_key, Action<Res> onSuccess, Action<BaseResponse> onError)
{
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 LoadGameData()
{
StorageLoad.Req req = new StorageLoad.Req();

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

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

[Serializable]
public class GameData
{
public int level;
public int score;
public string[] items;
}
데이터 역직렬화

storage_value를 JSON으로 저장했다면, JsonUtility.FromJson<T>()를 사용하여 원래 객체로 복원할 수 있습니다.

데이터 없음 처리

저장된 데이터가 없는 경우 에러가 반환됩니다. 초기 플레이어의 경우 이를 처리하여 기본값을 설정하세요.