Friends

Overview

The Friends service allows players to connect socially with other players. This service uses WebSocket to ensure all players get real-time updates about their Friend List. Players can manage their friends in several different ways, including:

  • Request Friend allows players to add another player as a friend using that player’s User ID. Players will be notified when they receive a friend request.
  • Accept Friend Request allows players to accept friend requests they’ve received. After the player accepts the request, the requester will be notified and the two players will be linked as friends.
  • Reject Friend Request allows players to deny a friend request from a player they don’t want to be friends with.
  • Cancel Friend Request allows players to cancel and remove a pending friend request they have sent to another player, in case they have changed their mind or sent the request to the wrong player.
  • Get Friendship Status shows players their friendship status with another player. Possible statuses include:
    • Not Friend indicates that the players are not connected as friends.
    • Outgoing Friend indicates that the friend request sent by the player to another player is still pending.
    • Incoming Friend indicates that the player has received a friend request that is still pending.
    • Friend indicates that the two players are connected as friends.
  • List of Friends shows the player all of the players they’re currently friends with.
  • List of Incoming Friends shows the player a list of players that have requested to be their friend. Players can accept or reject these requests.
  • List of Outgoing Friends shows players the list of pending friend requests they have sent to other players.
  • Unfriend allows players to stop being friends with other players. Unfriending a player will remove that player from their friend list. If the player wants to be friends with an unfriended player, they will have to send that player another friend request.

Tutorials

Search for a Player

You can search for a player’s account information using their Email Address or Display Name as the query. Please refer to the Search User endpoint.

string query = "YourFriendsEmailAddressOrDisplayName";
AccelBytePlugin.GetUser().SearchUsers(query, result =>
{
if (result.IsError)
{
Debug.Log(string.Format("Failed to search user: error code: {0} message: {1}", result.Error.Code, result.Error.Message));
}
else
{
PagedPublicUsersInfo pagedPublicUsers = result.Value;
foreach (var userInfo in pagedPublicUsers.data)
{
Debug.LogFormat("Get User, email: {0}, displayName: {1}, userId: {2}", userInfo.emailAddress, userInfo.displayName, userInfo.userId);
}
}
});

Friend Interactions

Send a Friend Request

The first step in making a friend is to send a friend request to another player.

AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().RequestFriend(userId, result =>
{
if (result.IsError)
{
Debug.LogFormat("Failed to send a friend request: error code: {0} message: {1}", result.Error.Code, result.Error.Message);
}
else
{
Debug.Log("Successfully send a friend request");
}
});

Accepting and Rejecting Friend Requests

After a friend request has been sent, the player who received the request can either accept or reject it.

AccelBytePlugin.GetLobby().AcceptFriend(userId, result =>
{
if (result.IsError)
{
Debug.LogFormat("Failed to accept a friend request: error code: {0} message: {1}", result.Error.Code, result.Error.Message);
}
else
{
Debug.Log("Successfully accept a friend request");
}
});
AccelBytePlugin.GetLobby().RejectFriend(userId, result =>
{
if (result.IsError)
{
Debug.LogFormat("Failed to reject a friend request: error code: {0} message: {1}", result.Error.Code, result.Error.Message);
}
else
{
Debug.Log("Successfully reject a friend request");
}
});

Retrieve the Friend List

Players can see a list of all of their friends.

AccelBytePlugin.GetLobby().LoadFriendsList(result =>
{
if (result.IsError)
{
Debug.LogFormat("cannot retrieve friend list: error code: {0} message: {1}", result.Error.Code, result.Error.Message);
}
else
{
foreach (var userId in result.Value.friendsId)
{
Debug.LogFormat("Friend userId = {0}", userId);
}
}
});

Retrieve the List of Incoming Friend Requests

Players can see who has sent them friend requests.

AccelBytePlugin.GetLobby().ListIncomingFriends(result =>
{
if (result.IsError)
{
Debug.LogFormat("cannot retrieve list of incoming friend request: error code: {0} message: {1}", result.Error.Code, result.Error.Message);
}
else
{
foreach (var userId in result.Value.friendsId)
{
Debug.LogFormat("Friend userId = {0}", userId);
}
}
});

Retrieve the List of Outgoing Friend Requests

Players can see a list of friend requests they have sent that are still pending.

AccelBytePlugin.GetLobby().ListOutgoingFriends(result =>
{
if (result.IsError)
{
Debug.LogFormat("cannot retrieve list of ongoing/pending friend request: error code: {0} message: {1}", result.Error.Code, result.Error.Message);
}
else
{
foreach (var userId in result.Value.friendsId)
{
Debug.LogFormat("Friend userId = {0}", userId);
}
}
});

Unfriend

Players can remove another player from their friend list.

AccelBytePlugin.GetLobby().Unfriend(userId, result =>
{
if (result.IsError)
{
Debug.LogFormat("failed to unfriend a friend: error code: {0} message: {1}", result.Error.Code, result.Error.Message);
}
else
{
Debug.Log("Successfully unfriend a friend!");
}
});

What’s Next?

  • Check out the API references for more information on how to implement the Friends service.
  • You can also read more about how to integrate a player account with 3rd party accounts on platforms such as Steam.