Skip to main content

Bulk Synchronization of Third-party Platform Friends

Last updated on

This process is used to connect players' friends from third-party platforms to AccelByte Cloud's IAM service. This process works in the background and is triggered automatically every time your game starts, or manually by interaction between a player and the game client.

To allow your players to sync their third-party platform friends lists with their AccelByte Cloud friends list, you must call user.BulkGetUserByOtherPlatformUserIds() and lobby.BulkRequestFriend() consecutively.

TArray<FString> ThirdPartyPlatformFriendId = {"12345abcd", "abcd12345"};
EAccelBytePlatformType PlatformType = EAccelBytePlatformType::Steam;

FRegistry::User.BulkGetUserByOtherPlatformUserIds(PlatformType, ThirdPartyPlatformFriendId, THandler<FBulkPlatformUserIdResponse>::CreateLambda([](const FBulkPlatformUserIdResponse& Result)
{
TArray<FString> UserIds;
for (auto UserData : Result.UserIdPlatforms)
{
UserIds.Add(UserData.UserId);
}

FAccelByteModelsBulkFriendsRequest BulkFriendsRequest;
BulkFriendsRequest.FriendIds = UserIds;

FRegistry::Lobby.BulkFriendRequest(BulkFriendsRequest, FVoidHandler::CreateLambda([]()
{
// Do something if BulkFriendRequest has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if BulkFriendRequest has an error
UE_LOG(LogTemp, Log, TEXT("Error BulkFriendRequest, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString ErrorMessage)
{
// Do something if BulkGetUserByOtherPlatformUserIds has an error
UE_LOG(LogTemp, Log, TEXT("Error BulkGetUserByOtherPlatformUserIds, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));