Friend Interactions
These are all features for how players can manage their friends.
Retrieve a Player's Public Code
You can retrieve a player's public code using the PublicId parameter.
- Unreal Engine
- Unity
const FString& InUserIds = "userId1, userId2";
Api::UserProfile UserProfileApi(InCredentials, FRegistry::Settings, FRegistry::HttpRetryScheduler);
UserProfileApi.BatchGetPublicUserProfileInfos(InUserIds, THandler<TArray<FAccelByteModelsPublicUserProfileInfo>>::CreateLambda([&](const TArray<FAccelByteModelsPublicUserProfileInfo>& Result)
{
UE_LOG(LogTemp, Log, TEXT("Public Id - User 1 = %s"), *Result[0].PublicId);
UE_LOG(LogTemp, Log, TEXT("Public Id - User 2 = %s"), *Result[1].PublicId);
}),
FErrorHandler::CreateLambda([&](int32 ErrorCode, const FString& ErrorMessage)
{
UE_LOG(LogTemp, Warning, TEXT("Error %d: %s"), ErrorCode, *ErrorMessage);
}));
public void GetUserProfilePublicInfoByPublicId(string publicId, ResultCallback<PublicUserProfile> callback)
{
Report.GetFunctionLog(GetType().Name);
if (!session.IsValid())
{
callback.TryError(ErrorCode.IsNotLoggedIn);
return;
}
coroutineRunner.Run(
api.GetUserProfilePublicInfoByPublicId(publicId, callback));
}
Retrieve the Friend List
Use the following function to retrieve a friends list.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetLoadFriendListResponseDelegate(AccelByte::Api::Lobby::FLoadFriendListResponse::CreateLambda([](const FAccelByteModelsLoadFriendListResponse& Result)
{
// Do something if LoadFriendListResponseDelegate has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if LoadFriendListResponseDelegate has an error
UE_LOG(LogTemp, Log, TEXT("Error LoadFriendListResponseDelegate, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
FRegistry::Lobby.LoadFriendsList();
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().LoadFriendsList(result =>
{
if (result.IsError)
{
// Do something if LoadFriendsList has an error
Debug.Log($"Error LoadFriendsList, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if LoadFriendsList has been successful
}
});
Send a Friend Request using a User ID
The first step in making a friend is sending a friend request to another player. Use this code to send a friend request using a User ID.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetRequestFriendsResponseDelegate(AccelByte::Api::Lobby::FRequestFriendsResponse::CreateLambda([](const FAccelByteModelsRequestFriendsResponse& Result)
{
// Do something if RequestFriendsResponseDelegate has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if RequestFriendsResponseDelegate has an error
UE_LOG(LogTemp, Log, TEXT("Error RequestFriendsResponseDelegate, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
FString UserId = FString("SomeUserId");
FRegistry::Lobby.RequestFriend(UserId);
string userId = "SomeTargetFriendUserId";
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().RequestFriend(userId, result =>
{
if (result.IsError)
{
// Do something if RequestFriend has an error
Debug.Log($"Error RequestFriend, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if RequestFriend has been successful
}
});
Send a Friend Request using a Public Code
The first step in making a friend is sending a friend request to another player. Use this code to send a friend request using a Public Code.
- Unreal Engine
- Unity
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();
const auto OnRequestFriendByPublicIdDone = Api::Lobby::FRequestFriendsResponse::CreateLambda([](const FAccelByteModelsRequestFriendsResponse& Result)
{
if(Result.Code == "0")
{
// do something when request success
}
else
{
// do something when request failed
}
});
ApiClient->Lobby.SetRequestFriendsByPublicIdResponseDelegate(OnRequestFriendByPublicIdDone);
ApiClient->Lobby.RequestFriendByPublicId(PublicId);
AccelBytePlugin.GetLobby().RequestFriendByPublicId(publicId, result =>
{
if (result.IsError)
{
// do something if operation failed
Debug.Log("Request friend error with message " + result.Error.Message);
}
else
{
// do something if request friend success
}
});
Retrieve a List of Incoming Friend Requests
Use this function to retrieve all the information about incoming friend requests. This function retrieves user ID which you can use to accept or reject each request.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetListIncomingFriendsResponseDelegate(AccelByte::Api::Lobby::FListIncomingFriendsResponse::CreateLambda([](const FAccelByteModelsListIncomingFriendsResponse& Result)
{
if (Result.Code == "0")
{
// Do something if ListIncomingFriendsResponseDelegate has been successful
}
else
{
// Do something if ListIncomingFriendsResponseDelegate has an error
}
}));
FRegistry::Lobby.ListIncomingFriends();
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().ListIncomingFriends(result =>
{
if (result.IsError)
{
// Do something if ListIncomingFriends has an error
Debug.Log($"Error ListIncomingFriends, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if ListIncomingFriends has been successful
}
});
Accept Incoming Friend Requests
After a friend request has been sent, the player who received the request can either accept or reject it. Use the following function to accept a friend request.
To see a list of incoming friend requests, you can retrieve a list of incoming friend requests.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetAcceptFriendsResponseDelegate(AccelByte::Api::Lobby::FAcceptFriendsResponse::CreateLambda([](const FAccelByteModelsAcceptFriendsResponse& Result)
{
if (Result.Code == "0")
{
// Do something if AcceptFriendsResponseDelegate has been successful
}
else
{
// Do something if AcceptFriendsResponseDelegate has an error
}
}));
FString UserId = FString("SomeUserId");
FRegistry::Lobby.AcceptFriend(UserId);
string userId = "SomeTargetedAcceptedFriendUserId";
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().AcceptFriend(userId, result =>
{
if (result.IsError)
{
// Do something if AcceptFriend has an error
Debug.Log($"Error AcceptFriend, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if AcceptFriend has been successful
}
});
Reject Incoming Friend Requests
You can reject the incoming friend request by their User ID. To get the user ID, you need to retrieve a list of incoming friend requests, copy the User ID, and store it somewhere safe for use in the following function.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetRejectFriendsResponseDelegate(AccelByte::Api::Lobby::FRejectFriendsResponse::CreateLambda([](const FAccelByteModelsRejectFriendsResponse& Result)
{
if (Result.Code == "0")
{
// Do something if RejectFriendsResponseDelegate has been successful
}
else
{
// Do something if RejectFriendsResponseDelegate has an error
}
}));
FString UserId = FString("SomeTargetRejectFriendUserId");
FRegistry::Lobby.RejectFriend(UserId);
string userId = "SomeTargetRejectedFriendUserId";
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().RejectFriend(userId, result =>
{
if (result.IsError)
{
// Do something if RejectFriend has an error
Debug.Log($"Error RejectFriend, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if RejectFriend has been successful
}
});
Retrieve a List of Outgoing Friend Requests
Use the following function to retrieve a list of outgoing friend requests.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetListOutgoingFriendsResponseDelegate(AccelByte::Api::Lobby::FListOutgoingFriendsResponse::CreateLambda([](const FAccelByteModelsListOutgoingFriendsResponse& Result)
{
if (Result.Code == "0")
{
// Do something if ListOutgoingFriendsResponseDelegate has an error
}
else
{
// Do something if ListOutgoingFriendsResponseDelegate has been successful
}
}));
FRegistry::Lobby.ListOutgoingFriends();
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().ListOutgoingFriends(result =>
{
if (result.IsError)
{
// Do something if ListOutgoingFriends has an error
Debug.Log($"Error ListOutgoingFriends, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if ListOutgoingFriends has been successful
}
});
Cancel Outgoing Friend Requests
You can cancel outgoing friend requests using User ID. To get the user ID, you need to retrieve a list of outgoing friend requests, copy the User ID, and store it somewhere safe for the following function.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetCancelFriendsResponseDelegate(AccelByte::Api::Lobby::FCancelFriendsResponse::CreateLambda([](const FAccelByteModelsCancelFriendsResponse& Result)
{
if (Result.Code == "0")
{
// Do something if CancelFriendsResponseDelegate has been successful
}
else
{
// Do something if CancelFriendsResponseDelegate has an error
}
}));
FString UserId = FString("SomeTargetCancelFriendUserId");
FRegistry::Lobby.CancelFriendRequest(UserId);
string userId = "SomeTargetOutgoingFriendUserId";
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().CancelFriendRequest(userId, result =>
{
if (result.IsError)
{
// Do something if CancelFriendRequest has an error
Debug.Log($"Error CancelFriendRequest, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if CancelFriendRequest has been successful
}
});
Unfriend
Use the following function to unfriend another player.
- Unreal Engine
- Unity
FRegistry::Lobby.Connect();
FRegistry::Lobby.SetUnfriendResponseDelegate(AccelByte::Api::Lobby::FUnfriendResponse::CreateLambda([](const FAccelByteModelsUnfriendResponse& Result)
{
if (Result.Code == "0")
{
// Do something if UnfriendResponseDelegate has been successful
}
else
{
// Do something if UnfriendResponseDelegate has an error
}
}));
FString UserId = FString("SomeTargetFriendUserId");
FRegistry::Lobby.Unfriend(UserId);
string userId = "SomeTargetFriendUserId";
AccelBytePlugin.GetLobby().Connect();
AccelBytePlugin.GetLobby().Unfriend(userId, result =>
{
if (result.IsError)
{
// Do something if Unfriend has an error
Debug.Log($"Error Unfriend, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if Unfriend has been successful
}
});