친구 요청
다른 사용자에게 친구 요청을 보냅니다.
URL 확인
이 API는 service-api.playnanoo.com 도메인을 사용합니다.
API 정보
- URL:
https://service-api.playnanoo.com/friend/v20231201/request - Method:
PUT - 인증 필요: 예
DeviceInfo 상속
이 API의 Req 클래스는 DeviceInfo를 상속받습니다. DeviceInfo의 모든 속성이 자동으로 포함됩니다.
요청 파라미터
| 파라미터 | 타입 | 필수 | 설명 |
|---|---|---|---|
| table_code | string | 필수 | 친구 테이블 코드 |
| open_id | string | 필수 | 친구 요청을 보낼 사용자의 오픈 ID |
응답 데이터
Res 클래스
| 필드 | 타입 | 설명 |
|---|---|---|
| Status | string | 처리 결과 상태 |
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 FriendRequest
{
static string path = "https://service-api.playnanoo.com/friend/v20231201/request";
[Serializable]
public class Req : DeviceInfo
{
public string table_code;
public string open_id;
public IEnumerator Send(string tableCode, string openId, Action<Res> onSuccess, Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(tableCode)) this.table_code = tableCode;
if (!string.IsNullOrEmpty(openId)) this.open_id = openId;
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}
[Serializable]
public class Res : BaseResponse
{
public string Status;
}
}
사용 예제
using PlayNANOO;
public class PlayNANOOExample : MonoBehaviour
{
void SendFriendRequest(string targetOpenId)
{
FriendRequest.Req req = new FriendRequest.Req();
StartCoroutine(req.Send(
tableCode: "friend_table",
openId: targetOpenId,
onSuccess: res =>
{
Debug.Log($"친구 요청 전송 성공: {res.Status}");
ShowMessage("친구 요청을 보냈습니다.");
},
onError: (error) =>
{
Debug.LogError($"친구 요청 전송 실패: [{error.ErrorCode}] [{error.Message}]");
ShowMessage("친구 요청 전송에 실패했습니다.");
}
));
}
void ShowMessage(string message)
{
// UI 메시지 표시
Debug.Log(message);
}
}
OpenID
OpenID는 랜덤 사용자 검색 API를 통해 얻을 수 있습니다.
중복 요청
이미 친구이거나 대기 중인 요청이 있는 경우 에러가 발생할 수 있습니다.