查询好友列表
查询已注册的好友列表。
URL 确认
此 API 使用 service-api.playnanoo.com 域名。
API 信息
- URL:
https://service-api.playnanoo.com/friend/v20231201/search - Method:
PUT - 需要认证: 是
DeviceInfo 继承
此 API 的 Req 类继承自 DeviceInfo。DeviceInfo 的所有属性将自动包含。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| table_code | string | 必填 | 好友表代码 |
响应数据
Res 类
| 字段 | 类型 | 说明 |
|---|---|---|
| Items | List<FriendItem> | 好友列表 |
FriendItem 类
| 字段 | 类型 | 说明 |
|---|---|---|
| RelationshipCode | string | 关系代码 |
| UserId | string | 用户 ID |
| Nickname | string | 昵称 |
| Timezone | string | 时区 |
| AccessSeconds | double | 最后访问时间 (秒) |
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 表示距最后访问以来经过的时间(秒)。可用于判断在线状态。