メインコンテンツまでスキップ

プラットフォームのフレンドを同期する

Last updated on December 5, 2024

Introduction

The AccelByte Gaming Services (AGS) Friend service allows players to synchronize first-party platform friends (e.g., Steam, Xbox, PlayStation, Epic, etc.) with the service. It will take the platformUserId from the first-party platform, and then map the friends relation with the existing AGS users.

Manually synchronize friends in bulk

This process requires the game client to manually get the first-party platform friendsId list, and then send it to the AGS IAM service to get the AGS userId. After getting the AGS UserId list, you can call the Friend service to add them into the friend list directly without any confirmation step. This process can be triggered every time your game starts or manually by interaction between a player and the game client.

To allow your players to synchronize their first-party platform friends lists with their AGS friends list, you must call user.BulkGetUserByOtherPlatformUserIds() and lobby.BulkRequestFriend() consecutively.

Image shows region active

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 succeeds
}), FErrorHandler::CreateLambda([](int32 ErrorCode,
const FString & ErrorMessage) {
// Do something if BulkFriendRequest fails
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 fails
UE_LOG(LogTemp, Log, TEXT("Error BulkGetUserByOtherPlatformUserIds, Error Code: %d Error Message: %s"), ErrorCode, * ErrorMessage);
}));

Endpoint reference

Get list of UserIds by PlatformUserIdshttps://prod.gamingservices.accelbyte.io/iam/apidocs/#/Users/PublicListUserIDByPlatformUserIDsV3
Add friends without confirmationhttps://prod.gamingservices.accelbyte.io/lobby/apidocs/#/friends/addFriendsWithoutConfirmation

Service-to-service synchronize friends

The AGS Friends service also provides a way for users to synchronize their first-party platform in a service-to-service (S2S) way. The game client only needs to call one endpoint and the AGS backend will get the friends data from the first-party platform, then map them to the AGS Friends relationship in the background. This process will also add the friends relation without the confirmation from the impacted users. However, this flow is currently limited to the AGS-supported platforms.

Image shows region active

FAccelByteModelsSyncThirdPartyFriendInfo field details:

Parameter NameTypeDescription
IsLoginBoolIf set to true, the currently logged in user platform token will be used.
PlatformIdFStringThe ID of the platform you want to synchronize the friend list into. Valid values are:steam, ps5, ps4.
PlatformTokenFStringThe user platform token to use when synchronizing. This can be left empty if IsLogin set to true.
PsnEnvFStringThe selected PlayStation (PSN) environment to synchronize friends with. Valid values are:sp-int, prod-qa, np
/*** Set delegate that will trigger after the sync is complete ***/
// ================================================================
bool bSyncDone {false};
bool bSyncSuccess {false};
TArray<FAccelByteModelsSyncThirdPartyFriendsResponse> SyncResponse;
const FOnSyncThirdPartyPlatformFriendsV2CompleteDelegate OnSyncComplete =
FOnSyncThirdPartyPlatformFriendsV2CompleteDelegate::CreateLambda([&](
int32 LocalUserNum, const FOnlineError& ErrorInfo, const TArray<FAccelByteModelsSyncThirdPartyFriendsResponse>& Response)
{
// If our operation succeeds
if(ErrorInfo.WasSuccessful())
{
// Check success state for sync to each platform
for(const FAccelByteModelsSyncThirdPartyFriendsResponse& Response : Responses)
{
if(Response.Status == "success")
{
UE_LOG(LogTemp, Display, TEXT("friend sync to platform %s success"), *Response.PlatformId);
}
else if(Result.Status == "failed")
{
UE_LOG(LogTemp, Display, TEXT("friend sync to platform %s failed"), *Response.PlatformId);
}
}
}
});

FriendsInterface->AddOnSyncThirdPartyPlatformFriendsV2CompleteDelegate_Handle(UserNum, OnSyncComplete);

/*** Execute friend sync ***/
// ================================================================

// Set request
FAccelByteModelsSyncThirdPartyFriendInfo RequestInfo1;
RequestInfo1.IsLogin = true;
RequestInfo1.PlatformId = FAccelByteUtilities::GetPlatformString(EAccelBytePlatformType::Steam);

FAccelByteModelsSyncThirdPartyFriendInfo RequestInfo2;
RequestInfo2.IsLogin = false;
RequestInfo2.PlatformId = FAccelByteUtilities::GetPlatformString(EAccelBytePlatformType::PS5);
RequestInfo2.PlatformToken = TEXT("platform-token")
RequestInfo2.PsnEnv = TEXT("sp-int")

FAccelByteModelsSyncThirdPartyFriendsRequest Request;
Request.FriendSyncDetails.Emplace(RequestInfo1);
Request.FriendSyncDetails.Emplace(RequestInfo2);

// Execute function
if(!FriendsInterface->SyncThirdPartyPlatformFriendV2(UserNum, Request))
{
UE_LOG(LogAccelByteOSSManualFriendSyncTest, Error, TEXT("friend sync third party platform friend failed, SyncThirdPartyPlatformFriendV2 returned false"));
return false;
}

Endpoint Reference

Sync Native Friendshttps://prod.gamingservices.accelbyte.io/lobby/apidocs/#/friends/syncNativeFriends