Skip to main content
Version: 5.11.4

Loading Friends List

1. Write a method for loading the friends list

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

BackendFriend.cs

Before editing

    public void GetFriendList() {
// Step 4. Loading Friends List
}

After editing

    public void GetFriendList() {
var bro = Backend.Friend.GetFriendList();

if(bro.IsSuccess() == false) {
Debug.LogError("An error occurred while loading the friends list. : " + bro);
return;
}

Debug.Log("Successfully loaded the friends list. : " + bro);

if(bro.FlattenRows().Count <= 0) {
Debug.Log("There are no friends.");
return;
}

int index = 0;

string friendListString = "Friends List\n";

foreach(LitJson.JsonData friendJson in bro.FlattenRows()) {
string nickName = friendJson["nickname"]?.ToString();
string inDate = friendJson["inDate"].ToString();

friendListString += $"{index}. {nickName} - {inDate}\n";
index++;
}

Debug.Log(friendListString);
}

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.

BackendManager.cs

Before editing(Step 3. Loading and Accepting Friend Requests)

    async void Test() {
await Task.Run(() => {

// Must be logged in as the user to which user2 sent the friend request in Step 2.
BackendLogin.Instance.CustomLogin("user1", "1234");

BackendFriend.Instance.GetReceivedRequestFriend(); // Loads friend requests list
BackendFriend.Instance.ApplyFriend(0); // Accepts the latest friend request on the friend requests list

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

After editing

    async void Test() {
await Task.Run(() => {

// Must be logged in as either the user who signed up in Step 2(the user who sent the friend request) or the user whose login proceeded in Step 3(recipient of the friend request).
BackendLogin.Instance.CustomLogin("user1", "1234");

BackendFriend.Instance.GetFriendList(); // Loads friends list

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 'Friends List'.
When errors, such as statusCode : 400, 404, and 409, occur instead of the above log, you can check which errors caused the failure in GetFriendList error case.