본문으로 건너뛰기

친구 목록 조회

등록된 친구 목록을 조회합니다.

URL 확인

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

API 정보

  • URL: https://service-api.playnanoo.com/friend/v20231201/search
  • Method: PUT
  • 인증 필요: 예
DeviceInfo 상속

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

요청 파라미터

파라미터타입필수설명
table_codestring필수친구 테이블 코드

응답 데이터

Res 클래스

필드타입설명
ItemsList<FriendItem>친구 목록

FriendItem 클래스

필드타입설명
RelationshipCodestring관계 코드
UserIdstring사용자 ID
Nicknamestring닉네임
Timezonestring타임존
AccessSecondsdouble마지막 접속 시간 (초 단위)

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 System.Collections.Generic;
using UnityEngine.Networking;

public class FriendAll
{
static string path = "https://service-api.playnanoo.com/friend/v20231201/search";

[Serializable]
public class Req : DeviceInfo
{
public string table_code;

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

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

[Serializable]
public class Res : BaseResponse
{
public List<FriendItem> Items;
}

[Serializable]
public class FriendItem
{
public string RelationshipCode;
public string UserId;
public string Nickname;
public string Timezone;
public double AccessSeconds;
}
}

사용 예제

기본 사용법

using PlayNANOO;
using System.Collections.Generic;

public class PlayNANOOExample : MonoBehaviour
{
void GetFriendList()
{
FriendAll.Req req = new FriendAll.Req();

StartCoroutine(req.Send(
tableCode: "your-friend-table-code",
onSuccess: res =>
{
Debug.Log($"친구 목록 조회 성공: {res.Items.Count}명");

foreach (var friend in res.Items)
{
Debug.Log($"친구: {friend.Nickname} (ID: {friend.UserId})");
Debug.Log($" 관계 코드: {friend.RelationshipCode}");
Debug.Log($" 마지막 접속: {friend.AccessSeconds}초 전");
}
},
onError: (error) =>
{
Debug.LogError($"친구 목록 조회 실패: [{error.ErrorCode}] [{error.Message}]");
}
));
}
}

친구 목록 UI 표시

using PlayNANOO;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;

public class FriendListUI : MonoBehaviour
{
public Transform friendListContainer;
public GameObject friendItemPrefab;

void Start()
{
LoadFriendList();
}

void LoadFriendList()
{
FriendAll.Req req = new FriendAll.Req();

StartCoroutine(req.Send(
tableCode: "friend_table",
onSuccess: res =>
{
DisplayFriendList(res.Items);
},
onError: (error) =>
{
Debug.LogError($"친구 목록 로드 실패: {error.Message}");
}
));
}

void DisplayFriendList(List<FriendAll.FriendItem> friends)
{
// 기존 목록 클리어
foreach (Transform child in friendListContainer)
{
Destroy(child.gameObject);
}

// 친구 목록 표시
foreach (var friend in friends)
{
GameObject item = Instantiate(friendItemPrefab, friendListContainer);

// UI 업데이트
Text nicknameText = item.transform.Find("Nickname").GetComponent<Text>();
Text statusText = item.transform.Find("Status").GetComponent<Text>();

nicknameText.text = friend.Nickname;

// 마지막 접속 시간 표시
if (friend.AccessSeconds < 300) // 5분 이내
{
statusText.text = "온라인";
statusText.color = Color.green;
}
else
{
int minutesAgo = (int)(friend.AccessSeconds / 60);
statusText.text = $"{minutesAgo}분 전 접속";
statusText.color = Color.gray;
}
}
}
}

친구 검색

using PlayNANOO;
using System.Collections.Generic;
using System.Linq;

public class FriendSearcher : MonoBehaviour
{
private List<FriendAll.FriendItem> allFriends;

void SearchFriend(string searchKeyword)
{
FriendAll.Req req = new FriendAll.Req();

StartCoroutine(req.Send(
tableCode: "friend_table",
onSuccess: res =>
{
allFriends = res.Items;

// 닉네임으로 검색
var searchResults = allFriends
.Where(f => f.Nickname.Contains(searchKeyword))
.ToList();

Debug.Log($"검색 결과: {searchResults.Count}명");

foreach (var friend in searchResults)
{
Debug.Log($"- {friend.Nickname}");
}
},
onError: (error) =>
{
Debug.LogError($"친구 검색 실패: {error.Message}");
}
));
}
}
테이블 코드

친구 기능을 사용하기 전에 PlayNANOO 관리자 콘솔에서 친구 테이블 코드를 생성해야 합니다.

접속 시간

AccessSeconds는 마지막 접속 이후 경과된 시간을 초 단위로 나타냅니다. 온라인 상태 판별에 활용할 수 있습니다.