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.
- Unreal Engine
- Unity
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);
}));
string[] thirdPartyPlatfromFriendId = { "12345abcd", "abcd12345" };
PlatformType platformType = PlatformType.Steam;
AccelBytePlugin.GetUser().BulkGetUserByOtherPlatformUserIds(platformType, thirdPartyPlatfromFriendId, result =>
{
if (result.IsError)
{
// Do something if BulkGetUserByOtherPlatformUserIds has an error
Debug.Log($"Error BulkGetUserByOtherPlatformUserIds, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
List<string> userIds = new List<string>();
foreach (var userData in result.Value.userIdPlatforms)
{
userIds.Add(userData.userId);
}
AccelBytePlugin.GetLobby().BulkRequestFriend(userIds.ToArray(), result =>
{
if (result.IsError)
{
// Do something if BulkRequestFriend has an error
Debug.Log($"Error BulkRequestFriend, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if BulRequestFriend has been successful
}
});
}
});