Skip to main content
Version: 5.11.2

Sending Friend Requests

1. Write a method for sending friend requests

Add content to the SendFriendRequest method in BackendFriend.cs written in Pre-arrangements.

BackendFriend.cs

Before editing

    public void SendFriendRequest(string nickName) {
// Adds logic of Step 2. Sending Friend Requests
}

After editing

    public void SendFriendRequest(string nickName) {
var inDateBro = Backend.Social.GetUserInfoByNickName(nickName);

if(inDateBro.IsSuccess() == false) {
Debug.LogError("An error occurred while searching the name of the user. : " + inDateBro);
return;
}

string inDate = inDateBro.GetReturnValuetoJSON()["row"]["inDate"].ToString();

Debug.Log($"inDate value of {nickName} is {inDate}.");

var friendBro = Backend.Friend.RequestFriend(inDate);

if(friendBro.IsSuccess() == false) {
Debug.LogError($"{inDate} An error occurred while sending a friend request. : " + friendBro);
return;
}

Debug.Log("Friend request sent successfully." + friendBro);
}

2. Add method call to BackendManager.cs

BackendManager, which is automatically called when the game is executed, must be used to call this method.
Add it so that the method may be called after BACKND initialization and BACKND login.

The user to log in must differ from the user who will send the friend request.

BackendManager.cs

Before editing

    async void Test() {
await Task.Run(() => {
BackendLogin.Instance.CustomLogin("user1", "1234");

// Adds logic for friend functions

Debug.Log("Test complete.");
});
}

After editing

    async void Test() {
await Task.Run(() => {
// Signed up as user2 because the friend request will be sent to user1
string user2Id = "user2";

// Sign up as user2Id(When 409 error occurs, change CustomSignUp to CustomLogin because an ID has already been created with user2Id)
BackendLogin.Instance.CustomSignUp(user2Id, "1234");
BackendLogin.Instance.UpdateNickname(user2Id); // Change the nickname to be same as the ID

string user1Nickname = "Desired Name"; // Nickname of user1(may differ depending on the user)
BackendFriend.Instance.SendFriendRequest(user1Nickname); // Method for sending friend requests

Debug.Log("Test complete.");
});
}

3. Test in Unity

After editing the script, execute Unity debugging and check the console log of Unity.

The method has been successfully called when the log displays 'Friend request sent successfully. : statusCode : 204'.
When errors, such as statusCode : 400, 404, and 409, occur instead of the above log, you can check which errors caused the failure in RequestFriend error case.