Skip to main content
Version: 6.0.0

Sending Friend Requests

1. Write a method for sending friend requests

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

BackndFriend.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 = Backnd.Player.GetPlayerInfoByDisplayName(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 = Backnd.Friend.SendFriendRequest(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 BackndManager.cs

BackndManager, 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.

BackndManager.cs

Before editing

    async void Test() {
await Task.Run(() => {
BackndLogin.Instance.CustomSignIn("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 CustomSignIn because an ID has already been created with user2Id)
BackndLogin.Instance.CustomSignUp(user2Id, "1234");
BackndLogin.Instance.ChangeDisplayName(user2Id); // Change the nickname to be same as the ID

string user1Nickname = "Desired Name"; // Nickname of user1(may differ depending on the user)
BackndFriend.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 SendFriendRequest error case.